虽然我的应用程序是一个 Web 应用程序,但它并没有使用太多 Spring 的 Web 控制器。它只是 REST(球衣)和套接字。我的应用程序中只有大约一半使用依赖注入。我的应用程序在我的main()
.
ServletRegistration jerseyServletRegistration = ctx.addServlet("JerseyServlet", new SpringServlet());
jerseyServletRegistration.setInitParameter("com.sun.jersey.config.property.packages", "com.production.resource");
jerseyServletRegistration.setInitParameter("com.sun.jersey.spi.container.ContainerResponseFilters", "com.production.resource.ResponseCorsFilter");
jerseyServletRegistration.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", Boolean.TRUE.toString());
jerseyServletRegistration.setInitParameter("com.sun.jersey.config.feature.DisableWADL", Boolean.TRUE.toString());
jerseyServletRegistration.setInitParameter("org.codehaus.jackson.map.DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY", Boolean.TRUE.toString());
jerseyServletRegistration.setLoadOnStartup(1);
jerseyServletRegistration.addMapping("/api/*");
//add atmosphere support
ServletRegistration socketRegistration = ctx.addServlet("AtmosphereServlet", new SocketInitializer());
socketRegistration.setLoadOnStartup(1);
//socketRegistration.addMapping("/socket/*");
//deploy
logger.info("Deploying server...");
ctx.deploy(server);
server.start();
//start the production process
Production.init();
System.in.read();
server.stop();
在Production
课堂上,我通过 加载我的服务ApplicationContextProvider
。 有没有更好的方法可以让我通过依赖注入加载所有资源?
public static void init() {
//add hook to trigger Production Shutdown sequence
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
public void run() {
Production.shutdown();
}
}));
logger.info("Initializing production workflows...");
productionService = (ProductionService) ApplicationContextProvider.getApplicationContext().getBean("productionService");
//load active workflows into memory
WorkflowService workflowService = (WorkflowService) ApplicationContextProvider.getApplicationContext().getBean("workflowService");
for (WorkflowEntity workflowEntity : workflowService.findActive()) {
logger.info(" - "+workflowEntity.getName()+"");
workflowList.add(Workflow.factory(workflowEntity));
}
bootup();
logger.info("Production initialized");
}