为什么我的Spring的声明事务失效了?

[b]DAO代码如下:[/b]

public class UserDAO extends BaseDAO {
public void insertTestData() {
Connection con = null;
PreparedStatement ps = null;
String sql = null;
try {
con = getConnection();
sql = "insert into oa_test_1(description) values(?)";
ps = con.prepareStatement(sql);
ps.setString(1, "TEST");
ps.execute();
String id = getIdentity(con);

if (1 == 1)
throw new RuntimeException();

sql = "insert into oa_test_2(description,parentid) values(?,?)";
ps = con.prepareStatement(sql);
ps.setString(1, "TEST_2");
setIntParam(ps, new Integer(id), 2);
ps.execute();
} catch (SQLException e) {
throw new RuntimeException();
} finally {
safeCloseStatementOrRs(ps);
safeCloseConnection(con);
}
}
}


public class BaseDAO {
private DataSource dataSource;

public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
}

public Connection getConnection() {
try {
return dataSource.getConnection();
} catch (Exception e) {
throw new RuntimeException();
}
}
}

[b]Service 代码如下:[/b]
public class UserManagerService {

private UserDAO userDao;

public void setUserDao(UserDAO userDao) {
this.userDao = userDao;
}

public User userLogon(String username, String password) {
userDao.insertTestData();
return null;
}
}

[b]Controller 代码如下:[/b]
public class PublicController extends MultiActionController {

private UserManagerService userService;

public void setUserService(UserManagerService userService) {
this.userService = userService;
}

public ModelAndView handleLogin(HttpServletRequest request,
HttpServletResponse response) throws ServletException {
try {
userService.userLogon("james", "12345688");
//WebUtils.setSessionAttribute(request, "user", user);
return new ModelAndView(new RedirectView("/cm/index.htm"));
} catch (Exception e) {
System.out.println("transaction failed.........................");
}
return null;
}
}

[b]配置如下:[/b]

<?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:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd">


<jee:jndi-lookup id="dataSource" jndi-name="jndi_cm"/>

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource"><ref local="dataSource"/></property>
</bean>

<bean id="userDao" class="com.cm.main.dao.UserDAO">
<property name="dataSource"><ref bean="dataSource"/></property>
</bean>

<bean id="userServiceTarget" class="com.cm.main.service.UserManagerService">
<property name ="userDao"><ref local="userDao"/></property>
</bean>

<bean id="userService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager"/>
</property>
<property name="target"><ref local="userServiceTarget"/></property>
<property name="transactionAttributes">
<props>
<prop key="*">
PROPAGATION_REQUIRED,-Exception
</prop>
</props>
</property>
</bean>

<bean id="publicController" class="com.cm.main.controller.PublicController">
<property name="methodNameResolver"><ref local="cmMethodNameResolver"/></property>
<property name="userService"><ref bean="userService"/></property>
</bean>
</beans>

Spring 为2.0版本,appServer 为Weblogic 813
我很疑惑为什么我的声明事务控制失败,操作结果为oa_test_1中插入了一条记录,我明明已经抛出了RuntimeException,事务为什么不回滚,我的Service 和 Dao都没有实现接口方式,而是直接进行实现类的注入,不知道这是否有关系?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值