我们正在使用 JavaConfig,我正在尝试设置一个单独的应用程序上下文来解决 Jersey 1.7 中的一些问题(即它包含所有路径中用 @Controller 注释的所有 Spring beans 的方式)。
我已经设置了 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 会使其识别为类名,但它似乎并没有这样做......
最佳答案
Spring 的DispatcherServlet
有support for AnnotationConfigWebApplicationContext
。但您没有使用 DispatcherServlet
,您使用的是一些 Jersey SpringServlet
.
关于java - Spring 将 servlet contextConfigLocation 类视为路径,尽管 contextClass 正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31884931/