关于Spring mvc 不会滚的问题

来源:互联网 发布:用阿里云搭建vpn 编辑:程序博客网 时间:2024/05/06 15:48

配置都是正常的配置

我就不贴出来了

关键在于 service 包的自动注入

一定要放在父容器中扫描,否则事务不能回滚

所谓 父容器

Spring 和 spring mvc 有点区别

简单的讲 spring是父容器

                    spring mvc是子容器(可能不太合适)

也就是说

<!-- service包(自动注入) --><context:component-scan base-package="demo.service" />

要放在applicationContext.xml中 如果放在springmvc.xml中 事务就会有问题 service不是父容器扫描出来的 事务不会回滚


 <welcome-file-list>    <welcome-file>index.jsp</welcome-file>  </welcome-file-list>    <context-param>    <param-name>contextConfigLocation</param-name>    <param-value>classpath:/config/applicationContext.xml</param-value> <!-- 父容器 -->  </context-param>  <filter>    <description>字符集过滤器</description>    <filter-name>encodingFilter</filter-name>    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>    <init-param>      <description>字符集编码</description>      <param-name>encoding</param-name>      <param-value>UTF-8</param-value>    </init-param>  </filter>  <filter-mapping>    <filter-name>encodingFilter</filter-name>    <url-pattern>/*</url-pattern>  </filter-mapping>  <listener>    <description>spring监听器</description>    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  </listener>  <listener>    <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>  </listener>  <servlet>    <servlet-name>SpringMVC</servlet-name>    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>    <init-param>      <description>spring MVC  配置文件</description>      <param-name>contextConfigLocation</param-name>      <param-value>classpath:/config/spring-mvc.xml</param-value><span style="font-size:24px;"><!-- 子容器 --></span>    </init-param>    <load-on-startup>1</load-on-startup>  </servlet>


0 0
原创粉丝点击