//init Spring context
//before we init the app context, we have to create a parent context with all the config objects others rely on to get initialized
AnnotationConfigWebApplicationContext parent = new AnnotationConfigWebApplicationContext();
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
parent.refresh();
parent.getBeanFactory().registerSingleton("configuration", configuration);
parent.registerShutdownHook();
parent.start();
//the real main app context has a link to the parent context
ctx.setParent(parent);
ctx.register(MyAppSpringConfiguration.class);
ctx.refresh();
ctx.registerShutdownHook();
ctx.start();
//now that Spring is started, let's get all the beans that matter into DropWizard
//health checks
Map<String, HealthCheck> healthChecks = ctx.getBeansOfType(HealthCheck.class);
for(Map.Entry<String,HealthCheck> entry : healthChecks.entrySet()) {
environment.healthChecks().register("template", entry.getValue());
}
//resources
Map<String, Object> resources = ctx.getBeansWithAnnotation(Path.class);
for(Map.Entry<String,Object> entry : resources.entrySet()) {
environment.jersey().register(entry.getValue());
}
@Configuration
//@ImportResource("classpath:myapp-security.xml")
@ComponentScan(basePackages = {"com.example.resources"})
public class MyAppSpringConfiguration {
}
And getting this exception:
ERROR [2014-04-18 06:12:34,552] com.sun.jersey.server.impl.application.RootResourceUriRules: The ResourceConfig instance does not contain any root resource classes.
Exception in thread "main" javax.servlet.ServletException: com.sun.jersey.spi.container.servlet.ServletContainer-358311fc@81642924==com.sun.jersey.spi.container.servlet.ServletContainer,1,false
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:561)
at org.eclipse.jetty.servlet.ServletHolder.initialize(ServletHolder.java:349)
at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:812)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:288)
Seems Spring is not able to find classes annotated with @Path. Any help here?