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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean name="/myssh/test.do" class="com.yourcompany.struts.action.TestAction"> </bean> <bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>
<bean id="man" name="man_name" class="springtest.Man">
<property name="message">
<value>你好! </value>
</property>
</bean>
<bean id="WxGzjgDAO" class="springdao.WxGzjgDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!-- 声明一个 Hibernate 3 的 事务管理器供代理类自动管理事务用 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean> <bean id="WxGzjgDAOProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <!-- 注意这个属性, 详细意义请参考文章开头的参考资料, 必须为 true 使用CGLIB才不用强制编写DAO接口 -->
<property name="proxyTargetClass">
<value>true </value>
</property> <property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="target">
<ref local="WxGzjgDAO" />
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED </prop>
</props>
</property>
</bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
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-2.5.xsd"> <bean name="/myssh/test.do" class="com.yourcompany.struts.action.TestAction"> </bean> <bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>
<bean id="man" name="man_name" class="springtest.Man">
<property name="message">
<value>你好! </value>
</property>
</bean>
<bean id="WxGzjgDAO" class="springdao.WxGzjgDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!-- 声明一个 Hibernate 3 的 事务管理器供代理类自动管理事务用 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean> <bean id="WxGzjgDAOProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <!-- 注意这个属性, 详细意义请参考文章开头的参考资料, 必须为 true 使用CGLIB才不用强制编写DAO接口 -->
<property name="proxyTargetClass">
<value>true </value>
</property> <property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="target">
<ref local="WxGzjgDAO" />
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED </prop>
</props>
</property>
</bean>
</beans>
解决方案 »
- servletContext关于io空指针
- 注意:ChatDemo.java 使用或覆盖了已过时的 API。 注意:要了解详细信息,请使用 -Xlint:deprecation 重新编译。
- java如何解析json数据变成一个对象?
- sqlserver 跟 oracle 用hibernate反向生成的pojo类跟xx.hbm.xml 文件的数据类型有什么区别啊?
- 我只是想知道我们的老师有没有讲错?
- 这是什么异常,怎样解决
- 如何当前时间加一天
- Struts+eclipse开发的WEB应用脱机浏览时TOMCAT发生java.net.unknownhostException
- jdom中,onclick="doAssign('<xsl:value-of select="roleid"/>')"出错
- POI解析excel 2007时,如何获取表格的高度和宽度呀!急求
- 为什么大型网站用php很多,而jsp很少
- Eclipse+hibernate出现如下问题:org.hibernate.hql.ast.QuerySyntaxException: DEPT is not mapped [from DEPT]
双手叩谢啊!!
可能是没有类库吧
把\spring-framework\lib\cglib下的jar包全部拷到工程的lib下去看看
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"><struts-config>
<data-sources />
<form-beans >
<form-bean name="testForm" type="com.yourcompany.struts.form.TestForm" /> </form-beans> <global-exceptions />
<global-forwards />
<action-mappings >
<!--action
attribute="testForm"
input="/form/test.jsp"
name="testForm"
path="/test"
scope="request"
type="com.yourcompany.struts.action.TestAction">-->
<action
attribute="testForm"
input="/form/test.jsp"
name="testForm"
path="/test"
scope="request"
type="com.yourcompany.struts.action.SpringProxyAction">
<forward name="faile" path="/jsp/faile.jsp" />
<forward name="success" path="/jsp/success.jsp" />
</action> </action-mappings> <message-resources parameter="com.yourcompany.struts.ApplicationResources" />
</struts-config>
你的是不是有什么方法或类是final的
检查一下看
在1.x里struts-config.xml中action的属性path的值,要和applicationContext.xml中<bean>的name属性值要一样!
你又没有用DelegatingActionProxy,这个bean还是用id吧,顺便换个好点的名字
要是用DelegatingActionProxy的话bean的那么就要与那个Acrion的配的path一致才行
估计问题还很大啊
呵呵
tomcat5.0,jdk1.4
是不是和这些版本有关呢?
<bean name="/myssh/test.do" class="com.yourcompany.struts.action.TestAction"> </bean>
这个写得怪怪的
你又没有用DelegatingActionProxy,这个bean还是用id属性吧,顺便换个好点的名字
要是用DelegatingActionProxy的话bean的name就要与那个Action配的path一致才行
估计问题还很大啊
呵呵
SpringProxyAction文件代码:
package com.yourcompany.struts.action;import java.util.*;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;public class SpringProxyAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String path = request.getRequestURI();
System.out.println(path);
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
Action action = (Action)ctx.getBean(path);
if(action != null) {
try {
return action.execute(mapping, form,
request, response);
} catch (Exception e) {
e.printStackTrace();
}
}
return mapping.findForward("faile");
}
}TestAction文件代码:
package com.yourcompany.struts.action;import java.text.ParseException;
import java.text.SimpleDateFormat;import springdao.WxGzjg;
import springdao.WxGzjgDAO;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.hibernate.Transaction;import com.yourcompany.struts.form.TestForm;public class TestAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws ParseException {
TestForm testForm = (TestForm) form;// TODO Auto-generated method stub
String xbrq = testForm.getXbjsrq();
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
java.util.Date cdate=df.parse(xbrq);
java.sql.Date dd=new java.sql.Date(cdate.getTime());
WxGzjg wxgzjg=new WxGzjg();
wxgzjg.setGzjg(testForm.getGzjg());
wxgzjg.setSfxyjy(testForm.getSfxyjy());
wxgzjg.setSfzhxyr(testForm.getSfzhxyr());
wxgzjg.setWxgzbh(testForm.getWxgzbh());
wxgzjg.setXbjsrq(dd);
wxgzjg.setXyrqx(testForm.getXyrqx());
WxGzjgDAO wxgzjgdao =new WxGzjgDAO();
wxgzjgdao.save(wxgzjg);
return mapping.findForward("success");
}
}
className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="classpath:applicationContext.xml" />
</plug-in>
把action 交给spring 管理!
中配置<bean name="/test" class="com.yourcompany.struts.action.TestAction">
<property id="你要在action里面实力操作数据的对象(这个对象要生成get set)">
<ref bean="上面你已经对操作数据类的配置。">
</property>
</bean>
建议你最好是搜个整合的小项目看看。或者是下个视频。也可以。《魔乐在线》的不错。
你的是不是有什么方法或类是final的
检查一下看