Results 1 to 2 of 2

Thread: Some objects set by @Autowired are null, others are set OK

  1. #1
    Join Date
    Apr 2012
    Posts
    4

    Default 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. #2
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,806

    Default

    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •