尽管正确的contextClass,Spring将servlet contextConfigLocation类视为路径

时间:2015-08-07 19:04:57

标签: java spring servlets jersey

我们正在使用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会使它识别为类名,但它似乎没有这样做......

1 个答案:

答案 0 :(得分:1)

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

It explicitly creates an XmlWebApplicationContext

相关问题