今天遇到两个问题。顺便做个笔记。以后遇到相同问题可以快速定位。
用的框架是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