Grizzly,共享spring生成的上下文
我有一个独立的spring项目,我需要用它启动一个嵌入式rest服务。 我可以用grizzly启动服务器,我的问题是,当我启动grizzly服务器时,它会创建自己的应用程序上下文。因此,无法通过REST服务访问父应用程序创建的实例 在Grizzly服务器和父应用程序之间是否有共享父应用程序上下文的方法,而不是获取Grizzly生成的应用程序上下文 这是我启动grizzly服务器的代码Grizzly,共享spring生成的上下文,spring,jersey,grizzly,Spring,Jersey,Grizzly,我有一个独立的spring项目,我需要用它启动一个嵌入式rest服务。 我可以用grizzly启动服务器,我的问题是,当我启动grizzly服务器时,它会创建自己的应用程序上下文。因此,无法通过REST服务访问父应用程序创建的实例 在Grizzly服务器和父应用程序之间是否有共享父应用程序上下文的方法,而不是获取Grizzly生成的应用程序上下文 这是我启动grizzly服务器的代码 public class RemotingServer { private HttpServer ht
public class RemotingServer {
private HttpServer httpServer;
private String host;
private int port;
public RemotingServer(String host, int port) {
this.host = host;
this.port = port;
}
public void init() throws Exception {
URI uri = UriBuilder.fromUri("http://" + host + "/").port(port).build();
ResourceConfig rc = new DefaultResourceConfig();
ConfigurableApplicationContext cac =
new ClassPathXmlApplicationContext("classpath:remoting-context.xml");
IoCComponentProviderFactory factory = new SpringComponentProviderFactory(rc, cac);
httpServer = GrizzlyServerFactory.createHttpServer(uri, rc, factory);
httpServer.start();
}
public void stop() {
httpServer.stop();
}
}
我也尝试将当前上下文设置为cac
的父级。然后我得到了以下异常
java.lang.IllegalStateException:BeanFactory未初始化或已关闭-在通过ApplicationContext访问Bean之前调用“刷新”
谢谢。试试这个:
ConfigurableApplicationContext cac =
new ClassPathXmlApplicationContext("classpath:remoting-context.xml");
// Have Spring load the context
cac.refresh();
IoCComponentProviderFactory factory = new SpringComponentProviderFactory(rc, cac);