springmvc.xml主要部分: <mvc:annotation-driven /> <context:annotation-config/> <context:component-scan base-package="com.sino.action" /> <context:component-scan base-package="com.sino.dao" /> <mvc:resources mapping="/img/**" location="/resource/images/" /> <mvc:resources mapping="/js/**" location="/resource/javascript/" /> <mvc:resources mapping="/css/**" location="/resource/css/" /> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix"><value>/resource/</value></property> <property name="suffix"><value>.jsp</value></property> </bean> spring-beans.xml主要部分: <!-- 数据源 --> <bean id="dataSource" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy"> <property name="targetDataSource"> <ref local="mainDataSource"/> </property> </bean> <!-- 数据库 事务管理器 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <!-- 根据Annotation来生成事务代理 --> <tx:annotation-driven transaction-manager="transactionManager"/> <bean id="testDao" class="com.ppxueche.dao.TestDao"> <property name="dataSource" ref="dataSource" /> </bean> web.xml部分: <servlet> <servlet-name>dispatch</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:/config/springmvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatch</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!-- spring bean配置 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:/config/spring-beans.xml</param-value> </context-param> 下面是测试类们: public interface IBaseDao { public void insert(); } TestDao.java public class TestDao extends JdbcDaoSupport implements IBaseDao { private static Logger logger = Logger.getLogger(TestDao.class); @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true) //此处如果注释掉依旧依旧可以插入数据,为什么呢? public void insert(){ int i = getJdbcTemplate().update("insert into test(test_name,test_content) values(""test_title"",""test_content2"")"); logger.info(i); } } TestAction.java @Controller @RequestMapping("/test") public class TestAction { @RequestMapping("/list") @ResponseBody public void queryTestByProperty(HttpServletRequest request){ IBaseDao dao = (IBaseDao)ApplicationContextManagement.getApplicationContext().getBean("testDao"); dao.insert(); } } 打印结果: TestDao.insert(TestDao.java:20) - 1 在TestDao的测试方法中如果把@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)这句去掉,依旧可以插入数据; |
|
我只是用到springmvc这块而已了,至于事务管理,应该是可以的。 |
|
20分 |
以前一直用spring,大概半年多年前发现有数据源死锁的问题,解决了2个月都无果,多方调查发现是spring的bug,而且spring基本上不认帐,连提问这个问题的帖子都删了,还是别用了。 |