私はスタンドアロンの春のプロジェクトを持っており、それで組み込みの休息サービスを開始する必要があります。グリズリーでサーバーを起動できる可能性があります。私の問題は、グリズリーサーバーを起動すると、独自のアプリケーションコンテキストが作成されることです。そのため、親アプリケーションによって作成されたインスタンスには、REST サービスからアクセスできません。
グリズリーで生成されたアプリケーションコンテキストを取得する以外に、グリズリーサーバーと親アプリケーションの間で親アプリケーションのコンテキストを共有する方法はありますか?
これは、グリズリー サーバーを起動するための私のコードです。
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 not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
ありがとう。