Spring AOP 和@Autowired 的问题
来源:互联网 发布:itudou官方下载mac 编辑:程序博客网 时间:2024/06/06 15:52
今天遇到两个问题。顺便做个笔记。以后遇到相同问题可以快速定位。
用的框架是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
- Spring AOP 和@Autowired 的问题
- Spring 的@Component和@Autowired
- 随笔-spring中的@Autowired无效的问题
- Spring @Autowired 注入集合类型的问题
- Spring @Autowired 注入集合类型的问题
- Spring之@Autowired问题
- Spring注解:@Autowired和@Resource的区别
- Spring 注释 @Autowired 和@Resource 的区别
- Spring 注解 @Resource和@Autowired的区别
- spring @resource 和 @autowired 的再认识
- spring的注解使用,Autowired和Qualifier
- Spring 注释 @Autowired 和@Resource 的区别
- Spring 注释 @Autowired 和@Resource 的区别
- Spring 注释 @Autowired 和@Resource 的区别
- Spring 注释 @Autowired 和@Resource 的区别
- Spring 注释 @Autowired 和@Resource 的区别
- spring 注解@Resource 和 @Autowired的区别
- Spring 注释 @Autowired 和@Resource 的区别
- scalaIDE 与spark2.0 源代码关联
- Java算法之二--二进制1的个数问题--位运算
- CI的session操作
- Android杂谈(14)OKHttp+Gson的简单使用
- EasyPlayer Android音频解码库(第二部分,封装解码器接口)
- Spring AOP 和@Autowired 的问题
- jquery购物车数量加减
- 抓取汽车之家新闻资讯做安卓app新闻资讯数据
- OC对象的内存分析
- CI数据库的相关操作&获取客户端IP
- 求和为n的连续正整数【经典面试题】
- 在win命令行执行python程序
- css初始化样式(重置默认样式)
- 安卓实时弹幕demo(一)弹幕效果