当前位置: 代码迷 >> J2EE >> 求教,关于spring的MethodInterceptor,该怎么处理
  详细解决方案

求教,关于spring的MethodInterceptor,该怎么处理

热度:31   发布时间:2016-04-17 23:21:18.0
求教,关于spring的MethodInterceptor
本帖最后由 u014164349 于 2015-01-13 15:11:11 编辑
public class doBeforeAdvice implements  MethodInterceptor{

@Override
public Object invoke(MethodInvocation arg0) throws Throwable {
// TODO 自动生成的方法存根
System.out.println("之前");
Object o=arg0.proceed();
System.out.println("之后");
return o;
}
}

这是类代码
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<bean id="helloSpring" class="com.entity.HelloSpring">
<property name="work" value="林冲"/>
<property name="man" value="军人"/>
</bean>
<bean id="doBefor" class="com.entity.doBeforeAdvice">
</bean>
<bean id="helloProxy" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>Text</value>
</property>
<property name="target">
<ref bean="helloSpring"/>
</property>
<property name="interceptorNames">
<list>
<value>
doBefor
</value>
</list>
</property>
</bean>
</beans>
这是XML配置文件
运行后报错:Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'helloProxy' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [java.lang.Class[]] for property 'proxyInterfaces'; nested exception is java.lang.IllegalArgumentException: Cannot find class [Text.java]. Root cause: java.lang.ClassNotFoundException: Text
老提示找不到这个Text,这个Ttext是我创建的一个接口,为什么老报错呢?

------解决思路----------------------
Failed to convert property value of type [java.lang.String] to required type [java.lang.Class[]] for property 'proxyInterfaces'; 

他说你这是类型转换错误了吧。你仔细看看你的代码是不是哪里用错了?
  相关解决方案