jersey
  1. jersey
  2. JERSEY-2235

Jersey-spring3 does not manage Spring profiles

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: 2.4
    • Fix Version/s: None
    • Component/s: containers, test-framework
    • Labels:
    • Environment:

      Mac OSX development machine, Eclipse

      Description

      I'm trying to configure a Jersey (2.4) test using Spring application context, using Spring profiles.

      My test class is this:

      OrderControllerTest.java
      public class OrderControllerTest extends JerseyTest {
      
          @Override
          protected Application configure() {
              enable(TestProperties.LOG_TRAFFIC);
              enable(TestProperties.DUMP_ENTITY);
              ApplicationResourceConfig config = new ApplicationResourceConfig();
              config.property("contextConfigLocation", "classpath:spring-context.xml");
              config.property("spring.profiles.active", "development");
              return config;
          }
      
      ...
      

      Where ApplicationResourceConfig class is this:

      ApplicationResourceConfig.java
      public class ApplicationResourceConfig extends ResourceConfig {
      
          public ApplicationResourceConfig() {
              register(RequestContextFilter.class)
              .register(OrderController.class);
          }
      
      ...
      

      and OrderController class is:

      OrderController.java
      @Component
      @Path("/order")
      @Produces(MediaType.APPLICATION_JSON)
      @Consumes(MediaType.APPLICATION_JSON)
      public class OrderController {
      
          @Autowired
          private OrderService orderService;
      
          @PUT
          public Response createOrder(String order) {
              return Response.ok().build();
          }
      ...
      

      The problem is that DI is not working (orderService is null). The DI is working well in other tests (not Jersey-based). I suppose the reason could be that Spring profile is not correctly loaded, since Spring logs say:

       
      426  [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver  - Searching for key 'spring.profiles.active' in [systemProperties]
      426  [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver  - Searching for key 'spring.profiles.active' in [systemEnvironment]
      426  [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver  - Could not find key 'spring.profiles.active' in any property source. Returning [null]
      

        Activity

        Hide
        Michal Gajdos added a comment -

        Properties from resource config (i.e. spring.profiles.active) except contextConfigLocation are not visible to Spring (and they are certainly not set to system properties).

        See http://stackoverflow.com/questions/20049699/jersey-2-4-test-with-spring-context-profile-di-not-working

        Show
        Michal Gajdos added a comment - Properties from resource config (i.e. spring.profiles.active) except contextConfigLocation are not visible to Spring (and they are certainly not set to system properties). See http://stackoverflow.com/questions/20049699/jersey-2-4-test-with-spring-context-profile-di-not-working
        Hide
        martin.mares added a comment -

        While it seems to be a valid issue, it is not critical to core functionality and we do not plan to dedicate resources to fixing the issue at the moment. In case you feel strongly about the issue, please consider contributing a fix by submitting a Github pull request.

        Show
        martin.mares added a comment - While it seems to be a valid issue, it is not critical to core functionality and we do not plan to dedicate resources to fixing the issue at the moment. In case you feel strongly about the issue, please consider contributing a fix by submitting a Github pull request.

          People

          • Assignee:
            Unassigned
            Reporter:
            paolo.boni
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Agile