Announcement Announcement Module
No announcement yet.
Some objects set by @Autowired are null, others are set OK Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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:

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

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

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

    <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

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