Search code examples
javaspringjerseyjersey-test-framework

Testing Jersey endpoints with members annotated with springs @Value


I'm trying to use Jersey and it's integration with Spring, in order to have jax-rs endpoints in our spring web-app.

The problem I have is that members of the application that are annotated with @Value isn't populated in our unit tests.

The ones that are populated with @Autowired works fine, and if I create a setter method for the string and annotate that with @Value that also works.

What annoys me is that members annotated directly with @Value doesn't work in the test, but work when deployed in our tomcat.

Is this a problem with our test configuration somehow? Or is this a known issue somewhere?

These are the relevant dependencies I think:

<dependency>
    <groupId>org.glassfish.jersey.ext</groupId>
    <artifactId>jersey-spring3</artifactId>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.test-framework</groupId>
    <artifactId>jersey-test-framework-core</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.test-framework.providers</groupId>
    <artifactId>jersey-test-framework-provider-jetty</artifactId>
    <scope>test</scope>
</dependency>

A small project that examplifies the problem here: https://github.com/alexanderkjall/jersey-jetty-interaction-example/blob/master/src/main/java/no/hackeriet/bugs/SpringRequestResource.java


Solution

  • Seems to be you might be missing component-scan, After adding it worked fine for me.

    <context:component-scan base-package="no.hackeriet.bugs" /> 
    

    but I am not sure how it still worked in tomcat without component-scan, which quite puzzles me.