-1
public interface Performance {
public void perform();
}
@Component
public class PerformanceImpl implements Performance {
@Override
public void perform() {
// TODO Auto-generated method stub
System.out.println(this.getClass()+"演出...");
}
}
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
//1、創建Spring的IOC的容器
ApplicationContext ctx = new ClassPathXmlApplicationContext("springXml/concertConfig.xml");
Performance p = ctx.getBean(Performance.class);
p.perform();
}
}
@Component
@Aspect
public class Audience {
@Pointcut("exection(** concert.Performance.perform(..))")
public void performance(){}
@Before("performance()")
public void silenceCellPhones(){
System.out.println("Silence cell phones");
}
@Before("performance")
public void takeSeats(){
System.out.println("Taking seats");
}
@AfterReturning("performance()")
public void applause(){
System.out.println("CLAP CLAP CLAP!");
}
@AfterThrowing("performance()")
public void demandRefund(){
System.out.println("Demanding a refund");
}
}
我已經注意這個問題,我不能最終解決切入點不能很好地形成:預計 ')' 字符位置12
的配置XML:
<context:component-scan base-package="concert"></context:component-scan>
<aop:aspectj-autoproxy> </aop:aspectj-autoproxy>
問題我遇到老友
六月 01, 2017 6:41:12 上午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
信息: Refreshing org[email protected]49c2faae: startup date [Thu Jun 01 06:41:12 CST 2017]; root of context hierarchy
六月 01, 2017 6:41:13 上午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [springXml/concertConfig.xml]
六月 01, 2017 6:41:13 上午 org.springframework.context.support.ClassPathXmlApplicationContext refresh
警告: Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'performanceImpl' defined in file [D:\cmj\MyProject\eclipse\springWorkspace\spring2\bin\concert\PerformanceImpl.class]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: Pointcut is not well-formed: expecting ')' at character position 12
exection(** concert.Performance.perform(..))
^^^^^^^
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:834)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at concert.Main.main(Main.java:11)
Caused by: java.lang.IllegalArgumentException: Pointcut is not well-formed: expecting ')' at character position 12
exection(** concert.Performance.perform(..))
^^^^^^^
at org.aspectj.weaver.tools.PointcutParser.resolvePointcutExpression(PointcutParser.java:316)
at org.aspectj.weaver.reflect.InternalUseOnlyPointcutParser.resolvePointcutExpression(InternalUseOnlyPointcutParser.java:36)
at org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate.getDeclaredPointcuts(Java15ReflectionBasedReferenceTypeDelegate.java:299)
at org.aspectj.weaver.ReferenceType.getDeclaredPointcuts(ReferenceType.java:790)
at org.aspectj.weaver.ResolvedType$PointcutGetter.get(ResolvedType.java:237)
at org.aspectj.weaver.ResolvedType$PointcutGetter.get(ResolvedType.java:235)
at org.aspectj.weaver.Iterators$4$1.hasNext(Iterators.java:213)
at org.aspectj.weaver.Iterators$4.hasNext(Iterators.java:230)
at org.aspectj.weaver.ResolvedType.findPointcut(ResolvedType.java:722)
at org.aspectj.weaver.patterns.ReferencePointcut.resolveBindings(ReferencePointcut.java:149)
at org.aspectj.weaver.patterns.Pointcut.resolve(Pointcut.java:188)
at org.aspectj.weaver.tools.PointcutParser.resolvePointcutExpression(PointcutParser.java:313)
at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:294)
at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:207)
at org.springframework.aop.aspectj.AspectJExpressionPointcut.checkReadyToMatch(AspectJExpressionPointcut.java:193)
at org.springframework.aop.aspectj.AspectJExpressionPointcut.getClassFilter(AspectJExpressionPointcut.java:170)
at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:194)
at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:248)
at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:280)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:118)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:88)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:69)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:330)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:293)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:422)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
... 11 more
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'performanceImpl' defined in file [D:\cmj\MyProject\eclipse\springWorkspace\spring2\bin\concert\PerformanceImpl.class]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: Pointcut is not well-formed: expecting ')' at character position 12
exection(** concert.Performance.perform(..))
^^^^^^^
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:834)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at concert.Main.main(Main.java:11)
Caused by: java.lang.IllegalArgumentException: Pointcut is not well-formed: expecting ')' at character position 12
exection(** concert.Performance.perform(..))
^^^^^^^
at org.aspectj.weaver.tools.PointcutParser.resolvePointcutExpression(PointcutParser.java:316)
at org.aspectj.weaver.reflect.InternalUseOnlyPointcutParser.resolvePointcutExpression(InternalUseOnlyPointcutParser.java:36)
at org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate.getDeclaredPointcuts(Java15ReflectionBasedReferenceTypeDelegate.java:299)
at org.aspectj.weaver.ReferenceType.getDeclaredPointcuts(ReferenceType.java:790)
at org.aspectj.weaver.ResolvedType$PointcutGetter.get(ResolvedType.java:237)
at org.aspectj.weaver.ResolvedType$PointcutGetter.get(ResolvedType.java:235)
at org.aspectj.weaver.Iterators$4$1.hasNext(Iterators.java:213)
at org.aspectj.weaver.Iterators$4.hasNext(Iterators.java:230)
at org.aspectj.weaver.ResolvedType.findPointcut(ResolvedType.java:722)
at org.aspectj.weaver.patterns.ReferencePointcut.resolveBindings(ReferencePointcut.java:149)
at org.aspectj.weaver.patterns.Pointcut.resolve(Pointcut.java:188)
at org.aspectj.weaver.tools.PointcutParser.resolvePointcutExpression(PointcutParser.java:313)
at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:294)
at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:207)
at org.springframework.aop.aspectj.AspectJExpressionPointcut.checkReadyToMatch(AspectJExpressionPointcut.java:193)
at org.springframework.aop.aspectj.AspectJExpressionPointcut.getClassFilter(AspectJExpressionPointcut.java:170)
at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:194)
at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:248)
at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:280)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:118)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:88)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:69)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:330)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:293)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:422)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
... 11 more
我看到問題similar,但它不能解決我的問題。爲什麼會出現這種錯誤
,而不是一個屏幕截圖,請包括代碼的文本,並在你的問題的錯誤消息(S)。 – BPS
感謝您的建議。現在我可以添加錯誤消息? – Tom