Announcement Announcement Module
Collapse
No announcement yet.
Some objects set by @Autowired are null, others are set OK Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Some objects set by @Autowired are null, others are set OK

    have been working on my first Spring project, and I've come across an annoying problem.

    I have a class called 'UsernameService' which is configured as a bean in the dispatcher-servlet.xml:

    Code:
    <bean id="usernameService" class="service.UsernameService" scope="session" >
        <aop:scoped-proxy />
    </bean>
    and when this bean is created in one of my classes (bean definition

    Code:
    <bean id="testController" class="controller.TestController" />
    as such:

    Code:
    @Autowired
    UsernameService uns;
    it works absolutely fine. However, when I try and do the same in another class, LogController:

    Code:
    <bean id="logController" class="controller.LogController" />
    then it does not work, and I get the following error:

    SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/flexitime] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause java.lang.NullPointerException
    I've managed to (I believe) ascribe this error to the fact that uns is never actually set/created and remains as null inside LogController.

    I have Googled this extensively and have found many 'solutions', however as yet none of them have worked. I also posted this exact question on stackoverflow, however none of the responses have helped me solve the issue.

    Thanks! James

  • #2
    Hello

    Read carefully these topics
    4.9.2 @Autowired
    4.10 Classpath scanning and managed components

    Comment

    Working...
    X