List of usage examples for org.springframework.web.context.support AnnotationConfigWebApplicationContext getBeanFactory
@Override
public final ConfigurableListableBeanFactory getBeanFactory()
From source file:sindica.to.dropwizard.spring.BaseSpringApplication.java
@Override public final void run(T configuration, Environment environment) throws ClassNotFoundException { AnnotationConfigWebApplicationContext parent = new AnnotationConfigWebApplicationContext(); AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); parent.refresh();/*from w w w .java2 s .co m*/ parent.getBeanFactory().registerSingleton("configuration", configuration); parent.registerShutdownHook(); parent.start(); //the real main app context has a link to the parent context ctx.setParent(parent); onConfigureSpringContext(ctx); ctx.refresh(); ctx.registerShutdownHook(); ctx.start(); //HealthChecks Map<String, HealthCheck> healthChecks = ctx.getBeansOfType(HealthCheck.class); for (Map.Entry<String, HealthCheck> entry : healthChecks.entrySet()) { LOG.info("Registering HealthCheck: ${entry.key}"); environment.healthChecks().register(entry.getKey(), entry.getValue()); } //resources Map<String, Object> resources = ctx.getBeansWithAnnotation(Path.class); for (Map.Entry<String, Object> entry : resources.entrySet()) { LOG.info("Registering Resource: ${entry.key}"); environment.jersey().register(entry.getValue()); } //tasks Map<String, Task> tasks = ctx.getBeansOfType(Task.class); for (Map.Entry<String, Task> entry : tasks.entrySet()) { LOG.info("Registering Task: ${entry.key}"); environment.admin().addTask(entry.getValue()); } //Managed Map<String, Managed> managers = ctx.getBeansOfType(Managed.class); for (Map.Entry<String, Managed> entry : managers.entrySet()) { LOG.info("Registering Task: ${entry.key}"); environment.lifecycle().manage(entry.getValue()); } //JAX-RS providers Map<String, Object> providers = ctx.getBeansWithAnnotation(Provider.class); for (Map.Entry<String, Object> entry : providers.entrySet()) { LOG.info("Registering Provider: ${entry.key}"); //environment.jersey().addProvider(entry.getValue()) } //last, but not least, let's link Spring to the embedded Jetty in Dropwizard EventListener servletListener = new SpringContextLoaderListener(ctx); environment.servlets().addServletListeners(servletListener); onRun(configuration, environment, ctx); }