Spring AOP 和@Autowired 的问题

今天遇到两个问题。顺便做个笔记。以后遇到相同问题可以快速定位。

用的框架是SSH

1、Spring AOP  报错 org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class.. 

最后找到的原因是 :public final class..  用final修饰了 改类  所以报错

解释:

This is a limitation in Spring AOP. When you use AspectJ pointcuts to weave aspects into beans, Spring will use CGLIB to generate a subclass of the target, and invoke the aspects from that subclass.

If the target class does not have a public default constructor, however, this will fail. CGLIB does have the ability to handle this, but this is all hidden behind the Spring AOP stuff and you can't change that behaviour.

I can only suggest that you go back to using setter injection for your controller, rather than constructor injection. It's not ideal, I know, but I can't think of any other workaround. 摘自:http://stackoverflow.com/questions/4490022/error-creating-bean-with-name-org-springframework-web-servlet-mvc-annotation-de

解决:把 final 去掉即可

2、Spring AOP 和@Autowired  冲突。action中@Autowired 不能注入。报空指针问题。

原因暂时不知道,后面如果知道原因。再补上。

解决方法:

方法一、去掉@Autowired,改用set,get注入
方法二、将action纳入spring的ioc管理
方法三、修改Struts.xml文件的属性<constant name="struts.objectFactory.spring.autoWire.alwaysRespect" value="true" />,使自动注入总是有效(我是用这个方法解决)

解决方法摘自:http://www.2cto.com/kf/201303/198693.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值