如题,action调用数据访问层,插入数据时不报错也不能插入,查询方法值全部返回true。另,service层和dao层均通过单元测试,可以正常运行、操作。但是集成action和jsp就会出问题。
使用了 <property name="connection.autocommit">true</property>。无效。上代码:
applicationcontext.xml
<?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: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.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean> <tx:annotation-driven transaction-manager="transactionManager" /> <aop:aspectj-autoproxy proxy-target-class="true"/>
<bean id="UserDAO" class="dao.UserDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" ></ref>
</property>
</bean>
<bean id="User_service" class="service.User_service" scope="prototype">
<property name="userDAO">
<ref bean="UserDAO" />
</property>
<bean id="register" class="Action.register" scope="prototype">
<property name="user_service">
<ref bean="User_service" />
</property>
</bean>
<bean id="login" class="Action.login" scope="prototype">
<property name="user_service">
<ref bean="User_service" />
</property>
</bean>
</beans>struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.objectFactory" value="spring"></constant>
<constant name="struts.custom.i18n.resources" value="globalMessages"/>
<package name="Light_Novel_System" extends="struts-default">
<action name = "register" class = "register">
<result name = "success">/login.jsp</result>
<result name = "error">/error.jsp</result>
<result name = "input">/register.jsp</result>
</action>
<action name = "login" class = "login">
<result name = "success">/welcom.jsp</result>
<result name = "error">/error.jsp</result>
</action>
</package></struts> register.java
@Transactional(propagation = Propagation.REQUIRED)
public class register extends ActionSupport{ /**
*
*/
private static final long serialVersionUID = 1L;
private User_service user_service;
private String username;
private String psw;
private String psw2;
public static BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext.xml");
public String excecute(){
User user = new User();
Date date = new Date();
user_service = (User_service)factory.getBean("User_service");
Date yesteday = new Date(date.getTime() - 1000 * 60 * 60 * 24);
user.setName(username);
user.setPsw(psw);
user.setScoredTime(yesteday);
Boolean success = user_service.newUser(user);
if(success){
return "success";
}
else return "error";
}
public void validate(){
super.validate();
if("".equals(username) || username == null){
this.addFieldError("user_name", this.getText("username_null"));
}
if("".equals(psw) || psw == null){
this.addFieldError("user_psw", this.getText("psw_null"));
}
if("".equals(psw2) || psw2 == null){
this.addFieldError("user_psw2", this.getText("psw2_null"));
}
if(!psw2.equals(psw)){
this.addFieldError("user_psw2", this.getText("psw2_not_equal"));
}
}
public void setUser_service(User_service user_service) {
this.user_service = user_service;
}
public User_service getUser_service() {
return user_service;
} public void setPsw2(String psw2) {
this.psw2 = psw2;
} public String getPsw2() {
return psw2;
} public void setUsername(String username) {
this.username = username;
} public String getUsername() {
return username;
} public void setPsw(String psw) {
this.psw = psw;
} public String getPsw() {
return psw;
}
}跪求解答!!不胜感激!!!!
使用了 <property name="connection.autocommit">true</property>。无效。上代码:
applicationcontext.xml
<?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: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.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean> <tx:annotation-driven transaction-manager="transactionManager" /> <aop:aspectj-autoproxy proxy-target-class="true"/>
<bean id="UserDAO" class="dao.UserDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" ></ref>
</property>
</bean>
<bean id="User_service" class="service.User_service" scope="prototype">
<property name="userDAO">
<ref bean="UserDAO" />
</property>
<bean id="register" class="Action.register" scope="prototype">
<property name="user_service">
<ref bean="User_service" />
</property>
</bean>
<bean id="login" class="Action.login" scope="prototype">
<property name="user_service">
<ref bean="User_service" />
</property>
</bean>
</beans>struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.objectFactory" value="spring"></constant>
<constant name="struts.custom.i18n.resources" value="globalMessages"/>
<package name="Light_Novel_System" extends="struts-default">
<action name = "register" class = "register">
<result name = "success">/login.jsp</result>
<result name = "error">/error.jsp</result>
<result name = "input">/register.jsp</result>
</action>
<action name = "login" class = "login">
<result name = "success">/welcom.jsp</result>
<result name = "error">/error.jsp</result>
</action>
</package></struts> register.java
@Transactional(propagation = Propagation.REQUIRED)
public class register extends ActionSupport{ /**
*
*/
private static final long serialVersionUID = 1L;
private User_service user_service;
private String username;
private String psw;
private String psw2;
public static BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext.xml");
public String excecute(){
User user = new User();
Date date = new Date();
user_service = (User_service)factory.getBean("User_service");
Date yesteday = new Date(date.getTime() - 1000 * 60 * 60 * 24);
user.setName(username);
user.setPsw(psw);
user.setScoredTime(yesteday);
Boolean success = user_service.newUser(user);
if(success){
return "success";
}
else return "error";
}
public void validate(){
super.validate();
if("".equals(username) || username == null){
this.addFieldError("user_name", this.getText("username_null"));
}
if("".equals(psw) || psw == null){
this.addFieldError("user_psw", this.getText("psw_null"));
}
if("".equals(psw2) || psw2 == null){
this.addFieldError("user_psw2", this.getText("psw2_null"));
}
if(!psw2.equals(psw)){
this.addFieldError("user_psw2", this.getText("psw2_not_equal"));
}
}
public void setUser_service(User_service user_service) {
this.user_service = user_service;
}
public User_service getUser_service() {
return user_service;
} public void setPsw2(String psw2) {
this.psw2 = psw2;
} public String getPsw2() {
return psw2;
} public void setUsername(String username) {
this.username = username;
} public String getUsername() {
return username;
} public void setPsw(String psw) {
this.psw = psw;
} public String getPsw() {
return psw;
}
}跪求解答!!不胜感激!!!!
再就是 struts.xml 打短点 跟中一下 看执行没执行进累 里 执行进了 说明 xml 对了,其次看连接