Announcement Announcement Module
Collapse
No announcement yet.
Injecting data using @Value into @Configurable classes Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Injecting data using @Value into @Configurable classes

    Hi,

    I'm trying to inject String using @Value into @Configurable class. Class itself is a JSF Converter, and therefore is not Spring managed. That's why I'm using @Configurable. Trick is, can I do that injection without defining prototype bean in my XML? Without prototype I get:

    Code:
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'pl.wroc.jug.jb.web.converter.DateConverter' is defined
    With prototype everything works as expected. My problem is: why I have to define this prototype when injecting using @Value, while when injecting using @Inject or @Autowire can do without prototype? Is it a feature or a bug? My prototype doesn't do anything interesting:

    Code:
    <bean class="pl.wroc.jug.jb.web.converter.DateConverter" scope="prototype"/>
    Best regards

    Jacek Bilski

  • #2
    @Value is replaced using a BeanFactoryPostProcessor which is only run BEFORE bean creation. Spring doesn't control the creation and hence cannot do anything with the @Value.

    @Autowired by default does dependency injection by type, if you use @Configurable it checks the application context and let that do autowiring. Now if you have a prototype bean of the same type of your @Configurable defined it is going to use that as the blue print to wire/configure your new bean.

    So it is neither a undocumented feature nor a bug it is the way an ApplicationContext works.

    Comment


    • #3
      Originally posted by Marten Deinum View Post
      @Value is replaced using a BeanFactoryPostProcessor which is only run BEFORE bean creation. Spring doesn't control the creation and hence cannot do anything with the @Value.

      @Autowired by default does dependency injection by type, if you use @Configurable it checks the application context and let that do autowiring. Now if you have a prototype bean of the same type of your @Configurable defined it is going to use that as the blue print to wire/configure your new bean.

      So it is neither a undocumented feature nor a bug it is the way an ApplicationContext works.
      Is this now possible in Spring 3? Is there any trickery I can use to get @Value to work with @Configurable?

      Comment

      Working...
      X