【问题标题】:Spring treating servlet contextConfigLocation class as path despite correct contextClass尽管 contextClass 正确,但 Spring 将 servlet contextConfigLocation 类视为路径
【发布时间】:2015-10-31 07:45:56
【问题描述】:

我们正在使用 JavaConfig,我正在尝试设置一个单独的应用程序上下文来解决 Jersey 1.7 中的一些问题(即,它包含所有路径中使用 @Controller 注释的所有 Spring bean 的方式)。

我已经设置了我想使用单独的应用程序上下文的 SpringServlet,如下所示:

<servlet>
    <servlet-name>My Servlet</servlet-name>
    <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
    <init-param>
         <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
         <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
        <param-value>com.sun.jersey.api.core.PackagesResourceConfig</param-value>
    </init-param>
    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>com.mycompany.admin</param-value>
    </init-param>
    <init-param>
        <param-name>contextClass</param-name>
        <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
    </init-param>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>com.mycompany.AdminWebConfig</param-value>
    </init-param>
</servlet>

但是,当我尝试访问其中一项服务时,Spring 不断给我以下错误;它试图将我的类名视为文件路径:

[2015-08-07 11:52:20,081] [ERROR] [] [request=] [user=] [ip=] [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/my-app].
[My REST Service]] [Allocate exception for servlet My REST Service] java.io.FileNotFoundException: Could not open ServletContext resource [/com.mycompany.AdminWebConfig]

有什么想法吗?我认为将 contextClass 设置为 org.springframework.web.context.support.AnnotationConfigWebApplicationContext 会使其将其识别为类名,但它似乎没有这样做......

【问题讨论】:

    标签: java spring servlets jersey


    【解决方案1】:

    Spring 的 DispatcherServletsupport for AnnotationConfigWebApplicationContext。但是你没有使用DispatcherServlet,你使用的是球衣SpringServlet

    It explicitly creates an XmlWebApplicationContext

    【讨论】:

    • 呸,确实如此。有人对解决这个问题有任何想法吗? Jersey 1 被证明是相当痛苦的。
    • @gdmitchell 扩展类并添加加载 AnnotationConfigWebApplicationContext 的行为(如果您想继续使用 Jersey)。
    • 我会看看我能做什么。我们要离开泽西岛,所以稍微修改一下可能不是什么大问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-27
    • 1970-01-01
    • 2018-12-10
    • 2018-12-09
    • 2018-09-05
    相关资源
    最近更新 更多