ssh框架整合。今天碰到了个奇怪的问题,先上代码
appilcationContx.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-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/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<!-- 注解的自动扫描,表示组件(如:@controler,@Service,@Repository,@Resource等)的扫描 ,注册到spring容器中-->
<context:component-scan base-package="com.softel.ele"></context:component-scan>
<!-- 创建由spring提供的sessionFactory,这是spring整合hibernate的核心 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
<!-- 创建事务管理器,由spring负责创建 -->
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 使用注解的形式管理事务 -->
<tx:annotation-driven transaction-manager="txManager"/>
</beans>
package com.softel.ele.serviceImpl;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.softel.ele.dao.IElecTestDao;
import com.softel.ele.domain.ElecTest;
import com.softel.ele.service.IElecTestService;
@Service(IElecTestService.SERVICE_NAME)
@Transactional(readOnly=true)
public class ElecTestServiceImpl implements IElecTestService {
@Resource(name=IElecTestDao.SERVICE_NAME)
private IElecTestDao elecTestDao;
/**
* isolalation事务隔离级别
* propagation事务的传播行为
* @param el
*/
@Transactional(isolation=Isolation.DEFAULT,propagation=Propagation.REQUIRED,readOnly=false)
public void save(ElecTest el){
elecTestDao.save(el);
}
}
struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<!-- 修改访问链接的后缀名 -->
<constant name="struts.action.extension" value="do"></constant>
<!-- 设置开发模式,开发时输出更多的错误信息 -->
<constant name="struts.devMode" value="true"></constant>
<!-- 修改ui主题为简单主题 -->
<constant name="struts.ui.theme" value="simple"></constant>
<package name="system" extends="struts-default" namespace="/system">
<action name="elecTextAction_*" class="com.softel.ele.action.ELecTestAction" method="{1}">
<result name="success">/system/textAdd.jsp</result>
</action>
</package>
</struts>
package com.softel.ele.action;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.opensymphony.xwork2.ModelDriven;
import com.softel.ele.domain.ElecTest;
import com.softel.ele.service.IElecTestService;
@SuppressWarnings("serial")
@Controller("eLecTestAction")
@Scope(value="prototype")
public class ELecTestAction extends BaseAction implements ModelDriven<ElecTest>{