这个错误即红色部分提示的错误,不知道advice类型的异常,说白了就是编写的spring通知的错误,这种错误比较常见,也是出于马虎的错误,比如前者通知、后置通知、环绕通知、异常通知、引入通知等这几个通知中的任何一个通知类忘了写继承的父类;以下列出这几个通知的类编写所继承的类:
前置通知:
public class BeforeAdvice implements MethodBeforeAdvice
后置通知:
public class AfterAdvice implements AfterReturningAdvice
环绕通知:
public class AroundAdvice implements MethodInterceptor
异常通知:
public class ThrowAdvice implements ThrowsAdvice
引入通知:
public class AuditableImpl extends DelegatingIntroductionInterceptor implements Auditable
14. 错误十四
java.lang.ClassCastException:
$Proxy10 cannot be cast to www.csdn.spring.proxy.advice.Auditable
java.lang.ClassCastException:
$Proxy11 cannot be cast to www.csdn.spring.proxy.advice.Auditable
像以上这个出现$ProxyXX cannot be cast to www.csdn.spring.proxy.advice.Auditable;什么代理不能强转成某一个类型的错误,一般都是在使用JDK动态代理或cglib代理的时候出现的错误,错误原因有:
1).JDK动态代理与cglib代理混淆,比如使用cglib代理时不能实现接口,你可能在使用的时候使用了cglib代理,但是却实现了接口,如果你在spring配置文件中使用aspectjs来进行通知,又想使用cglib接口那么你需要做的是目标类不实现接口,spring配置文件中配置aop的时候加上下面红色部分。
2)同样是使用aspectjs通知的时候,尤其是使用引入通知的时候,一定不要忘了让引用通知的业务类加上注解@Aspect;还要注意的是你使用的引入目标类和其实现接口的类路径一定要正确,我这里就范了一个小错误,到错包的错:
package www.csdn.spring.proxy.advice.aspectjs;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.DeclareParents;
@Aspect
publicclass AuditableService {
@DeclareParents(value="*..*Service*", defaultImpl = AuditableImpl.class)
public Auditable auditable;
}
我在使用Auditable接口的时候倒错了包,这里其实类都在同一包下,根本不用倒包,但是我从上一个包中复制代码的时候自动给我引入了上一个包的Auditable类;以后一定要注意了
15. 错误十五
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem:
Offending resource: file [F:\csdn-study\MyWorkspace\springHelloJava\bin\spring-pojoXmlAspectjs.xml]
Aspect: ref=''
这个错误顾名思义,这里已经提示的很清了,这里列出这个错误是对那些对pojo-xml配置通知不太熟悉的同学而言;这个错误就是在对应的spring配置文件中使用aop切面的时候忘写了一个ref熟悉的错,具体案例代码如下,注意下面的红色部分,错误就出在红色部分忘了写ref="adviceService":
implement-interface="www.csdn.spring.proxy.advice.aspectjs.pojoxml.Auditable" default-impl="www.csdn.spring.proxy.advice.aspectjs.pojoxml.AuditableImpl" /> id="myPcut" /> id="myPcuts" /> 16. 错误十六 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'deptDaoImpl' defined in class path resource [spring-dao.xml]: Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities) 关键是蓝色部分,蓝色部分已经给出了提示:不匹配的构造器,这种错误出在spring配置中,使用namedParameterJdbcTemplate时出的错,错误出在下面: class="org.sp