Results 1 to 2 of 2

Thread: Autowiring works in unit tests but not on server

  1. #1
    Join Date
    May 2011
    Posts
    1

    Default Autowiring works in unit tests but not on server

    This is kind of an abstract question.

    I am maintaining some code that has been hacked together with bits of Spring via annotations.

    I was able to unit test some of my Dao code by getting the class from the application context, but when i run it on the server im getting null pointers all over.

    The best part is, when the application starts up the beans get created, i have a log message in one of the Autowire setter methods that's firing.

    Now i was able to bypass this by making the needed attribute static, and in the methods manually building the objects.

    My question is, does this sound like a moderately common problem?
    All that i've been finding on the web were things like forgetting either
    <context:annotation-config /> or
    <context:component-scan base-package="com.hp"/>

    which are in my applicationContext

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,629

    Default

    Common problems are, creating the object twice (multiple component-scan elements), creating instances yourself instead of getting them from the applicationcontext. IN general it is configuration. So post your configuration (including web.xml) using [ code][/code ] tags !!! (that way it remains readable)...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

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