【问题标题】:Deploy Spring and Jersey App with JavaConfig on Grizzly在 Grizzly 上使用 JavaConfig 部署 Spring 和 Jersey 应用程序
【发布时间】:2013-06-16 21:25:43
【问题描述】:

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

我想将我的应用程序部署在一个 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 吗?或者有人对如何完成这项工作有更好的想法?

【问题讨论】:

    标签: spring deployment jersey applicationcontext grizzly


    【解决方案1】:

    试试这个

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

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

    【讨论】:

      猜你喜欢
      • 2014-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-12
      相关资源
      最近更新 更多