Announcement Announcement Module
No announcement yet.
@Configurable LTW and JUnit pitfall Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • @Configurable LTW and JUnit pitfall

    Hello community,

    I just wanted to let people know about a pitfall I ran into and hope to save someone some time. Spring version is 3.0.

    If you use @Configurable annotations and load time weaving make sure to not have any annotated class of yours within test-method-signatures. I used factory-methods to create dummy objects for testing, returning objects of classes annotated with @Configurable. This caused the test to load the class too eagerly and spring would not be able to weave / recognize this in time which resulted in failing to inject dependencies within these objects. I worked around by returning "Object" and casted within the test-method to the actual class.

    Regards Jakob

    EDIT: Switched to a static factory class, which solves this issue...
    Last edited by Jakob O.; Nov 2nd, 2010, 09:02 PM.

  • #2
    Well, I also had a similar problem of yours a few days ago. It is also possible to have your @Configurable instances not dependency injected because of interferences with other intergration tests dealing with them as well. In order to overcome such interference problems, you can mark those test cases with @DirtiesContext, so that tests with @Configurable instances can work. I think, according to this issue in Spring JIRA (, we have to wait for a general solution a bit more...