0

I've done a lot of searches an I can't find an example of a Jersey 2.x junit test that uses Spring managed resource beans.

The following is what I'm trying and it isn't working. It errors that MySpringManagedResource does not have a no argument constructor, which suggests it is just ignoring Spring.

public class MyServiceUnitTest extends JerseyTest {
    @Override
    protected Application configure() {
        return new ResourceConfig(MySpringManagedResource.class).
                register(org.glassfish.jersey.server.spring.SpringComponentProvider.class).
                register(MySpringConfigBean.class);
    }

    ...
}
user2684301
  • 2,550
  • 1
  • 24
  • 33
  • 1
    Check out my answer [to this question](http://stackoverflow.com/questions/20148269/restful-service-interface-with-jersey/20577797#20577797). You can provide Jersey with your own class that takes responsibility for instantiating resources (or obtaining them from Spring as Spring-managed beans). Although my answer involved interfaces, I don't see why it wouldn't work with classes as well. – John R Jan 14 '14 at 17:41

1 Answers1

0

Thank you John R. that led me to the solution. I would mark yours as the correct answer if I could. I ultimately used this:

@Override
protected Application configure() {
    ApplicationContext context = new AnnotationConfigApplicationContext(MyConfigClass.class);
    MyJerseyResource restResource = context.getBean(MyJerseyResource.class);

    return new ResourceConfig().registerInstances(restResource);
}
user2684301
  • 2,550
  • 1
  • 24
  • 33