Announcement Announcement Module
Collapse
No announcement yet.
Autowired annontation completely ignored Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Autowired annontation completely ignored

    I have a very simple bean that's annotated with @Service and has an @Autowired property. I'm using context:component-scan in the configuration file which works fine to load the service bean. However, nothing I do seems to get the container to recognize the @Autowired annotation on the property. In fact if I state @Autowired(required=true) the bean still loads with no error, but the property is injected.

    The relevant lines in the configuration are:
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:sec="http://www.springframework.org/schema/security"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-2.5.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schem...ontext-2.5.xsd
    http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.4.xsd"
    >
    ...
    <context:annotation-config/>
    <bean id="domainA" class="org.ccf.roswell.access.AccessControlDomainS ervice"/>
    <context:component-scan base-package="org.ccf.roswell" />
    ...

    The relevant lines in code are:

    @Service("Repository")
    public class RepositoryService implements org.ccf.roswell.repository.Repository
    {
    @Autowired(required=true)
    private AccessControlDomain accessControlDomain=null;
    ...

    There is a setter and getter for the property, but the documentation indicates that I can set the @Autowired on the field itself. When I do place the Autowired statement on the setter it makes no difference. All the beans load, but it's like the container completely ignores the Autowired annotation.

    I was running this under 3.0.0M1, but switched to 2.5.6 to see if that made a difference. I'm not up to the point that I need the features of 3.0.0M1 yet. I've included all the dependent Jar files I can identify. Is there something that I'm missing to trigger Autowiring?

  • #2
    Update on Autwired ignored

    When I removed the following tag, (which was loading the "Repository" bean,) and added the next tag, the bean loaded and autowired, but I can't determine at this time if it's using the annotations or simply filling in the empty properties.

    *doesn't work - for autowired*
    <context:component-scan base-package="org.ccf.roswell" />

    *does autowired*
    <bean id="Repository" class="org.ccf.roswell.repository.RepositoryServic e" autowire="byType"/>

    This means that I can continue with my development, but I'm concerned I'm missing something in the configuration or maybe the dependencies.

    Further update --- I tried placing @PostContruct on an init method - The annotation was ignored. Obviously I'm missing something that triggers annotation processing. Can anybody please give me a hint?
    Last edited by kimbaltrue; Feb 19th, 2009, 01:23 PM. Reason: Updated status

    Comment


    • #3
      Working with ApplicationContext in 2.5.6

      Okay, I switched to an ApplicationContext and called refresh. It's not clear in the documentation that the BeanPostProcessors etc... are not called with straight BeanFactories. However, I had to fall back to 2.5 because 3.0M1 doesn't work unless you have the magic copy of Antlr.

      Just to satisfy my curiosity, is there a way to get the BeanPostProcessors to run with a BeanFactory or do you always need an ApplicationContext?

      Comment


      • #4
        Originally posted by kimbaltrue View Post
        Okay, I switched to an ApplicationContext and called refresh. It's not clear in the documentation that the BeanPostProcessors etc... are not called with straight BeanFactories. However, I had to fall back to 2.5 because 3.0M1 doesn't work unless you have the magic copy of Antlr.

        Just to satisfy my curiosity, is there a way to get the BeanPostProcessors to run with a BeanFactory or do you always need an ApplicationContext?
        Reference docs:

        3.8.1. BeanFactory or ApplicationContext?
        Short version: use an ApplicationContext unless you have a really good reason for not doing so. For those of
        you that are looking for slightly more depth as to the 'but why' of the above recommendation, keep reading.

        Comment

        Working...
        X