struts+spring+hibernate整合问题(unable to proxy method) ---初学

yanzi0 2008-11-21 02:50:01
2008-11-21 11:22:48,328 WARN [org.springframework.aop.framework.Cglib2AopProxy] - Unable to proxy method [public final org.hibernate.SessionFactory org.springframework.orm.hibernate3.support.HibernateDaoSupport.getSessionFactory()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
2008-11-21 11:22:48,328 WARN [org.springframework.aop.framework.Cglib2AopProxy] - Unable to proxy method [public final org.springframework.orm.hibernate3.HibernateTemplate org.springframework.orm.hibernate3.support.HibernateDaoSupport.getHibernateTemplate()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
2008-11-21 11:22:48,328 WARN [org.springframework.aop.framework.Cglib2AopProxy] - Unable to proxy method [public final void org.springframework.orm.hibernate3.support.HibernateDaoSupport.setSessionFactory(org.hibernate.SessionFactory)] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
2008-11-21 11:22:48,343 WARN [org.springframework.aop.framework.Cglib2AopProxy] - Unable to proxy method [public final void org.springframework.orm.hibernate3.support.HibernateDaoSupport.setHibernateTemplate(org.springframework.orm.hibernate3.HibernateTemplate)] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
2008-11-21 11:22:48,359 WARN [org.springframework.aop.framework.Cglib2AopProxy] - Unable to proxy method [public final void org.springframework.dao.support.DaoSupport.afterPropertiesSet() throws java.lang.IllegalArgumentException,org.springframework.beans.factory.BeanInitializationException] because it is final: All calls to this method via a proxy will be routed directly to the proxy.


action注入到spring中报错。到调用hibernate中的save方法时抛出异常,数据不能正常保存到数据表里。
...全文
1249 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
lovelong1981 2011-11-10
  • 打赏
  • 举报
回复
这个问题不影响使用,你使用了自动事务的原因
csg103 2011-03-25
  • 打赏
  • 举报
回复
我用的是struts2哦。。也是这个问题,,没有任何的final类。。。。郁闷死了 搞了好久也没找出原因 难道是有包冲突。。??
tiyuzhongxin789 2008-11-21
  • 打赏
  • 举报
回复
CGLIB使用的是继承的方式,不能代理final的类或方法
你的是不是有什么方法或类是final的
检查一下看
lixiaolong3399 2008-11-21
  • 打赏
  • 举报
回复
这个问题是你配置文件上的问题。你需要在三个地方配置,1,web.xml上。然后是struts-config.xml上配置个插件。最后是你要在applicationContext.xml
中配置<bean name="/test" class="com.yourcompany.struts.action.TestAction">
<property id="你要在action里面实力操作数据的对象(这个对象要生成get set)">
<ref bean="上面你已经对操作数据类的配置。">
</property>
</bean>
建议你最好是搜个整合的小项目看看。或者是下个视频。也可以。《魔乐在线》的不错。

川籍黑人 2008-11-21
  • 打赏
  • 举报
回复
对了,还得在struts-config.xml中加上

<plug-in
className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="classpath:applicationContext.xml" />
</plug-in>


把action 交给spring 管理!
川籍黑人 2008-11-21
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 dreamhunter_lan 的回复:]
靠,上面写错了点

XML code<bean name="/myssh/test.do" class="com.yourcompany.struts.action.TestAction"> </bean>


这个写得怪怪的
你又没有用DelegatingActionProxy,这个bean还是用id属性吧,顺便换个好点的名字
要是用DelegatingActionProxy的话bean的name就要与那个Action配的path一致才行
估计问题还很大啊
呵呵
[/Quote]

如果是1.2的话,照上面的说的改下吧!


yanzi0 2008-11-21
  • 打赏
  • 举报
回复
这句是用于测试action与spring连接用的。


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

}
dreamhunter_lan 2008-11-21
  • 打赏
  • 举报
回复
靠,上面写错了点
<bean name="/myssh/test.do" class="com.yourcompany.struts.action.TestAction"> </bean>

这个写得怪怪的
你又没有用DelegatingActionProxy,这个bean还是用id属性吧,顺便换个好点的名字
要是用DelegatingActionProxy的话bean的name就要与那个Action配的path一致才行
估计问题还很大啊
呵呵
yanzi0 2008-11-21
  • 打赏
  • 举报
回复
我用的是struts1.2+sping2.5+hibernate3.2
tomcat5.0,jdk1.4
是不是和这些版本有关呢?
dreamhunter_lan 2008-11-21
  • 打赏
  • 举报
回复
<bean name="/myssh/test.do" class="com.yourcompany.struts.action.TestAction"> </bean>

这个写得怪怪的
你又没有用DelegatingActionProxy,这个bean还是用id吧,顺便换个好点的名字
要是用DelegatingActionProxy的话bean的那么就要与那个Acrion的配的path一致才行
估计问题还很大啊
呵呵
yanzi0 2008-11-21
  • 打赏
  • 举报
回复
我用的是struts1.2
川籍黑人 2008-11-21
  • 打赏
  • 举报
回复
用的struts2吗?

struts2没看,听说和1.X区别挺大!


在1.x里struts-config.xml中action的属性path的值,要和applicationContext.xml中<bean>的name属性值要一样!

dreamhunter_lan 2008-11-21
  • 打赏
  • 举报
回复
CGLIB使用的是继承的方式,不能代理final的类或方法
你的是不是有什么方法或类是final的
检查一下看
yanzi0 2008-11-21
  • 打赏
  • 举报
回复
类库在工程里面有。
yanzi0 2008-11-21
  • 打赏
  • 举报
回复
struts-config.xml的配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<!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>

dreamhunter_lan 2008-11-21
  • 打赏
  • 举报
回复
使用CGLIB的代理是需要类库支持的
可能是没有类库吧
把\spring-framework\lib\cglib下的jar包全部拷到工程的lib下去看看
川籍黑人 2008-11-21
  • 打赏
  • 举报
回复
struts-config.xml的配置呢?
yanzi0 2008-11-21
  • 打赏
  • 举报
回复
请高人多多帮忙,急啊!刚接触spring不知问题出在哪里了!!
双手叩谢啊!!
yanzi0 2008-11-21
  • 打赏
  • 举报
回复
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>


67,538

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧