问题描述
- 急急急!!!springMVC 注解事务失效
-
- spring-hibernate.xml
*<?xml version=""1.0"" encoding=""UTF-8""?>
xmlns:context=""http://www.springframework.org/schema/context"" xmlns:p=""http://www.springframework.org/schema/p""
xmlns:mvc=""http://www.springframework.org/schema/mvc"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
xmlns:tx=""http://www.springframework.org/schema/tx"" xmlns:aop=""http://www.springframework.org/schema/aop""
xsi:schemaLocation=""http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
>
class=""org.springframework.jdbc.datasource.DriverManagerDataSource"">com.mysql.jdbc.Driver
jdbc:mysql://localhost:3306/shuxiang?useUnicode=true&characterEncoding=UTF8
root
sxmd
class=""org.springframework.orm.hibernate4.LocalSessionFactoryBean"">
org.hibernate.dialect.MySQLDialect
update
falsecom.demo.model
class=""org.springframework.orm.hibernate4.HibernateTransactionManager"">
- spring-main.xml
<?xml version=""1.0"" encoding=""UTF-8""?>
xmlns:context=""http://www.springframework.org/schema/context"" xmlns:p=""http://www.springframework.org/schema/p""
xmlns:mvc=""http://www.springframework.org/schema/mvc"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
xmlns:tx=""http://www.springframework.org/schema/tx""
xmlns:aop=""http://www.springframework.org/schema/aop""
xsi:schemaLocation=""http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
> - spring-servlet.xml
<?xml version=""1.0"" encoding=""UTF-8""?>
xmlns:context=""http://www.springframework.org/schema/context"" xmlns:p=""http://www.springframework.org/schema/p""
xmlns:mvc=""http://www.springframework.org/schema/mvc"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
xmlns:tx=""http://www.springframework.org/schema/tx"" xmlns:aop=""http://www.springframework.org/schema/aop""
xmlns:beans=""http://www.springframework.org/schema/beans"" xmlns:util=""http://www.springframework.org/schema/util""
xsi:schemaLocation=""http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.2.xsd
>
<!-- 自动扫描的包名 --><!-- 默认的注解映射的支持 -->
class=""org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"">
application/json;charset=UTF-8
class=""org.springframework.web.multipart.commons.CommonsMultipartResolver"">
- web.xml
<?xml version=""1.0"" encoding=""UTF-8""?>index.jsp
contextConfigLocation
classpath*:spring-main.xmlorg.springframework.web.context.ContextLoaderListener
springMVC
org.springframework.web.servlet.DispatcherServletcontextConfigLocation
classpath*:spring-servlet.xml1
encodingFilter
org.springframework.web.filter.CharacterEncodingFilterencoding
UTF-8forceEncoding
trueencodingFilter
/*springMVC
.dohibernateFilter
org.springframework.orm.hibernate4.support.OpenSessionInViewFiltersingleSession
truesessionFactoryBeanName
sessionFactoryhibernateFilter
.doFaces Servlet
javax.faces.webapp.FacesServlet
1Faces Servlet
.facesAdminUserFilter
com.demo.manage.action.AdminUserFilterAdminUserFilter
.do
*测试controller
package com.demo.action;import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;import com.demo.model.UserModel;
@Controller
@RequestMapping(""test"")
@Transactional
public class TestAction extends AbstractAction{
@RequestMapping(""test"")
@ResponseBody
@Transactional(rollbackFor=Exception.class)
public String test(int id) throws Exception{
String sql=""update usertable set vip=2 where usersID=2"";
entityPersist.writeBySql(sql);if(id==2){ throw new RuntimeException(""cuowu ""); } return ""ok"";}
}
- spring-hibernate.xml