Hibernate JAP + Spring (MVC),在控制层中没有处理,如何进行通过配置文件进行事务控制? 本帖最后由 lvzhuze 于 2011-06-10 10:48:48 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我也是新手,希望对你有所帮助<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <!-- 开启注解处理器 --> <context:annotation-config/> <!-- 定义使用C3P0连接池的数据源 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <!-- 指定连接数据库的JDBC驱动 --> <property name="driverClass"> <value>com.mysql.jdbc.Driver</value> </property> <!-- 连接数据库所用的URL --> <property name="jdbcUrl"> <value>jdbc:mysql://localhost:3306/db_user?useUnicode=true&characterEncoding=gbk</value> </property> <!-- 连接数据库的用户名 --> <property name="user"> <value>root</value> </property> <!-- 连接数据库的密码 --> <property name="password"> <value>root</value> </property> <!-- 设置数据库连接池的最大连接数 --> <property name="maxPoolSize"> <value>20</value> </property> <!-- 设置数据库连接池的最小连接数 --> <property name="minPoolSize"> <value>2</value> </property> <!-- 设置数据库连接池的初始化连接数 --> <property name="initialPoolSize"> <value>2</value> </property> <!-- 设置数据库连接池的连接的最大空闲时间,单位为秒 --> <property name="maxIdleTime"> <value>20</value> </property> </bean> <!-- 注册一个JDBC数据源事务管理器 --> <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <!-- 基于AOP技术的事务管理实现 --> <aop:config> <!-- 定义一个事务切入点,拦截test.spring.dao.impl.UserDaoImpl中的所有方法 --> <aop:pointcut id="transactionPointcut" expression="execution(* test.spring.dao.impl.UserDaoImpl.*(..))"/> <!-- 引用txAdvice事务通知 --> <aop:advisor advice-ref="txAdvice" pointcut-ref="transactionPointcut"/> </aop:config> <!-- 定义一个事务通知txAdvice --> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <!-- 所有以load开头的方法声明为不需要事务 --> <tx:method name="load*" read-only="true" propagation="NOT_SUPPORTED"/> <!-- 其它所有方法声明为默认的REQUIRED类型的事务传播方式 --> <tx:method name="*"/> </tx:attributes> </tx:advice> <!-- 注册一个JdbcTemplate实例名称为jdbcTemplate --> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> <constructor-arg ref="dataSource"/> </bean> <!-- 注册一个UserDaoImpl实例名称为dao --> <bean id="dao" class="test.spring.dao.impl.UserDaoImpl"/> <!-- 注册一个UserServiceImpl实例名称为service --> <bean id="service" class="test.spring.service.impl.UserServiceImpl"/> <!-- 注册一个UserAction实例名称为userAction --> <bean id="userAction" class="test.spring.action.UserAction"/></beans> 业务类注解了 @Trans什么什么那个 很简单的问题,很菜的,请帮忙! jsf action执行问题 跪求,struts2 应该怎么测试? java中的灵异异常???? "~"字符全角编码是多少,怎么转为半角?只需要"~" 如何在表格中自动增加行,并对输入的数据作判断 连库时出现这个错误:JDBC SQLSERVER"Error establishing socket" poi设置边框 软件问题! JAVA接收邮件得到正文 学习Servlet,上哪儿找类库?
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- 开启注解处理器 -->
<context:annotation-config/>
<!-- 定义使用C3P0连接池的数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!-- 指定连接数据库的JDBC驱动 -->
<property name="driverClass">
<value>com.mysql.jdbc.Driver</value>
</property>
<!-- 连接数据库所用的URL -->
<property name="jdbcUrl">
<value>jdbc:mysql://localhost:3306/db_user?useUnicode=true&characterEncoding=gbk</value>
</property>
<!-- 连接数据库的用户名 -->
<property name="user">
<value>root</value>
</property>
<!-- 连接数据库的密码 -->
<property name="password">
<value>root</value>
</property>
<!-- 设置数据库连接池的最大连接数 -->
<property name="maxPoolSize">
<value>20</value>
</property>
<!-- 设置数据库连接池的最小连接数 -->
<property name="minPoolSize">
<value>2</value>
</property>
<!-- 设置数据库连接池的初始化连接数 -->
<property name="initialPoolSize">
<value>2</value>
</property>
<!-- 设置数据库连接池的连接的最大空闲时间,单位为秒 -->
<property name="maxIdleTime">
<value>20</value>
</property>
</bean>
<!-- 注册一个JDBC数据源事务管理器 -->
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 基于AOP技术的事务管理实现 -->
<aop:config>
<!-- 定义一个事务切入点,拦截test.spring.dao.impl.UserDaoImpl中的所有方法 -->
<aop:pointcut id="transactionPointcut" expression="execution(* test.spring.dao.impl.UserDaoImpl.*(..))"/>
<!-- 引用txAdvice事务通知 -->
<aop:advisor advice-ref="txAdvice" pointcut-ref="transactionPointcut"/>
</aop:config>
<!-- 定义一个事务通知txAdvice -->
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<!-- 所有以load开头的方法声明为不需要事务 -->
<tx:method name="load*" read-only="true" propagation="NOT_SUPPORTED"/>
<!-- 其它所有方法声明为默认的REQUIRED类型的事务传播方式 -->
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
<!-- 注册一个JdbcTemplate实例名称为jdbcTemplate -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg ref="dataSource"/>
</bean>
<!-- 注册一个UserDaoImpl实例名称为dao -->
<bean id="dao" class="test.spring.dao.impl.UserDaoImpl"/>
<!-- 注册一个UserServiceImpl实例名称为service -->
<bean id="service" class="test.spring.service.impl.UserServiceImpl"/>
<!-- 注册一个UserAction实例名称为userAction -->
<bean id="userAction" class="test.spring.action.UserAction"/>
</beans>
业务类注解了 @Trans什么什么那个