在Grizzly上使用JavaConfig部署Spring和Jersey应用程序



我试着让这个运行几天了,我不知道该怎么做。也许其他人已经有了想法或者已经这么做了?

我想在grizzly嵌入式服务器上部署我的应用程序。我使用JavaConfig配置了我的Spring应用程序,到目前为止效果还不错,但现在我似乎被卡住了。下面是我用来将Jersey的东西部署到grizzly的代码:

    HttpServer server = new HttpServer();
    NetworkListener listener = new NetworkListener("grizzly2", "localhost", 4433);
    server.addListener(listener);
    WebappContext ctx = new WebappContext("ctx","/");
    final ServletRegistration reg = ctx.addServlet("spring", new SpringServlet());
    reg.addMapping("/*");
    reg.setInitParameter("com.sun.jersey.config.property.packages", "com.myapp.http.webservices");
    ctx.addContextInitParameter("contextConfigLocation", "com/myapp/config/beans.xml");
    ctx.addListener("org.springframework.web.context.ContextLoaderListener");         
    ctx.addListener("org.springframework.web.context.request.RequestContextListener");
    ctx.addFilter("springSecurityFilterChain", new DelegatingFilterProxy());
    ctx.deploy(server);
    server.start();

现在,据我所知,下面这行是问题所在。

ctx.addContextInitParameter("contextConfigLocation", "com/myapp/config/beans.xml");

我有一个beans.xml,其中我配置了spring安全的东西,但我使用的所有其他bean都是通过JavaConfig声明的。因此,如果我只传递beans.xml,应用程序将只能访问其中声明的bean。我真正想要做的是传递我的ApplicationContext,这样我所有的bean都可以被正确检索。

我有一种方法来传递我的ApplicationContext与部署以及?或者有人有更好的办法来实现这个目标?

试试这个

ctx.addContextInitParameter("contextConfigLocation", "classpath:com/myapp/config/beans.xml")

您不应该再使用com.sun.jersey.config.property.packages,因为您已经使用Spring来管理bean。

最新更新