关于spring的MethodInterceptor

J2EE 码拜 9年前 (2015-04-04) 1009次浏览 0个评论
 
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是我创建的一个接口,为什么老报错呢?

关于spring的MethodInterceptor
40分
Failed to convert property value of type [java.lang.String] to required type [java.lang.Class[]] for property “”proxyInterfaces””; 

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


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明关于spring的MethodInterceptor
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!