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

DAO代码如下:

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();
}
}
}

Service 代码如下:
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;
}
}

Controller 代码如下:
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;
}
}

配置如下:

<?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都没有实现接口方式,而是直接进行实现类的注入,不知道这是否有关系?

你可能感兴趣的:(DAO,spring,sql,xml,weblogic)