I want initialize a verticle instance on deploy with spring context (all is annotations based with @Configurations etc.) and then be able to test it in integration tests,
My verticle:
public class MyServiceVerticle extends AbstractVerticle {
final VerticleStringContextLoader verticleStringContextLoader = new VerticleStringContextLoader(
"com.my.config",
MyConfig.class
);
@Override
public void start(Future<Void> startFuture) {
verticleStringContextLoader.connectWithVertx(vertx);
verticleStringContextLoader.onStart(startFuture);
}
@Override
public void stop() {
verticleStringContextLoader.onStop();
}
}
In the VerticleStringContextLoader
I load spring beans that are loaded with verticle itself.
Like this:
sharedContext = new AnnotationConfigApplicationContext();
sharedContext.register(VertxConfig.class);
...
sharedContext.scan(componentScanPackages);
sharedContext.refresh();
In tests, I would like to control spring context so that I could be able to have access to to those beans that are loaded.
In the integration test: when I deploy my verticle:
@RunWith(VertxUnitRunner.class)
....
vertx.deployVerticle(
MyServiceVerticle.class.getName(),
deploymentOptions,
testContext.asyncAssertSuccess( id -> {
...
})
);
The question is.. I guess I just shortcut like that:
How from the test that deployes a verticle and initializes the spring I could have access/references to Loaded Spring beans ?
Oh.. I guess I can do it in 3.5 version of vert.x (I use 3.4.2) -
there is a proper method for it when deploy.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.