jeudi 24 décembre 2015

How to get Spring Bean from JerseyTest subclass

Here is my abstract class which starts Jersey with given Spring context:

public abstract class AbstractJerseyTest extends JerseyTest {

public void setUp() throws Exception {
    super.setUp();
}

@AfterClass
public void destroy() throws Exception {
    tearDown();
}

@Override
protected URI getBaseUri() {
    return URI.create("http://localhost:9993");
}

@Override
protected Application configure() {
    RestApplication application = new RestApplication();

    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true);
    properties.put("contextConfigLocation", "classpath:spring-context-test.xml");

    application.setProperties(properties);
    application.register(this);
    return application;
}
}

So, the problem is that I need to access Spring bean from my test to populate database with some data.

Jersey version is 2.6

Also I found a similar question here

But it's related to Jersey 1.x so it doesn't work for Jersey 2.x

Could anyone point me in the right direction?

Aucun commentaire:

Enregistrer un commentaire