我正在使用Spring Web MVC作为与事务(所有注释驱动)的hibernate前端。我设置的web.xml如下:在Spring应用程序中处理* -context.xml和applicationContext.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>wdman</display-name>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>wdman</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>wdman</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<!-- Disables Servlet Container welcome file handling.
Needed for compatibility with Servlet 3.0 and Tomcat 7.0 -->
<welcome-file-list>
<welcome-file></welcome-file>
</welcome-file-list>
</web-app>
我不明白是怎么样的<tx:annotation-driven/>
从根上下文中继承选项(在这种情况下,一个定义的applicationContext.xml)到* -servlet.xml后缀上下文。它似乎不起作用。我在这两个文件中都有component-scan
以便让应用程序工作。这可以吗?组件是否重复?
您能否帮助或指出我的一些简要文档描述这些上下文如何合并?
感谢您的回复。我试图将'component-scan'仅添加到applicationContext.xml中 - 这会查找并实例化所有组件(包括@Controller注释的类)(通过jvisualm尝试)。但是应用程序似乎没有调度请求('所请求的资源()不可用。)。如果我将所有内容都放在* -servlet.xml中,它就会起作用。但这是一个非常糟糕的解决方案,因为我想提供各种其他前端。 –
谢谢!你的建议最终导致我找到了解决方案。在'* -servlet.xml'现在我只有:' context:component-scan>'。在applicationContext.xml中有互补过滤器(排除@Controller)。 –