|
精华帖 (0) :: 良好帖 (0) :: 新手帖 (5) :: 隐藏帖 (0)
|
|
|---|---|
| 作者 | 正文 |
|
时间:2008-05-26
最近一个崭新的项目使用了Java6,但在使用spring2.5.4的时候碰到了问题,下面是异常: Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resourceService' defined in class path resource [com/xxx/aop/aop.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut logReturnVal 但切换到Java5下就没有问题了,代码如下: package com.xxx.aop;
public interface ResourceService {
public String findResource(int resId);
}
package com.xxx.aop;
public class ResourceServiceImpl implements ResourceService {
public String findResource(int resId) {
return "Resource: " + resId;
}
}
package com.xxx.aop;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
@Aspect
public class LogPointCut {
@Pointcut("execution(public * com.xxx.aop.ResourceServiceImpl.findResource(..))")
public void logReturnVal(){}
}
package com.xxx.aop;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
@Aspect
public class LogAspect {
@AfterReturning(pointcut="com.xxx.aop.LogPointCut.logReturnVal()", returning="retVal")
public void afterReturn(String retVal){
System.out.println("Return:" + retVal);
}
}
package com.xxx.aop;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:com/xxx/aop/aop.xml");
ResourceService service = (ResourceService) context.getBean("resourceService");
service.findResource(10);
}
}
配置文件 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd" default-autowire="byName"> <aop:aspectj-autoproxy/> <bean id="resourceService" class="com.xxx.aop.ResourceServiceImpl" /> <bean class="com.xxx.aop.LogAspect" /> </beans>
完整代码见附件,由于不想换成Java5了,所以请教怎么在Java6中解决上述问题。 声明:JavaEye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
|
|
| 返回顶楼 | |
|
时间:2008-05-29
@Pointcut("execution(public * com.xxx.aop.ResourceServiceImpl.findResource(..))")
改为 @Pointcut("execution(public * com.xxx.aop.ResourceService.findResource(..))") 指向接口。我一试果然行了。虽然我spring二流,Annotation没入门,这个问题还真难。哇咔咔! |
|
| 返回顶楼 | |
|
时间:2008-05-30
默认delegating接口
|
|
| 返回顶楼 | |
浏览 715 次



