- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 AOP 新手。阅读《Spring in Action》一书。有 AOP 章节和示例。我用 XML 做了它并且一切正常。有 Aspects 的注释配置示例。我已经按照书上的那样做了一对一,但是它不起作用。请帮忙。
错误:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'guitar' defined in class path resource [springIdolBeansAnnotation.xml]:
Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 c
an't find referenced pointcut performance
包含名为 springIdolBeansAnnotation.xml 的 bean 的文件:
<?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:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<bean id="guitar" class="com.springinaction.springidol.Guitar"/>
<aop:aspectj-autoproxy/>
<bean id="kenny2" class="com.springinaction.springidol.Instrumentalist">
<property name="song" value="Jingle B"/>
<property name="instrument" ref="guitar"/>
</bean>
<bean id="audience" class="com.springinaction.springidol.Audience"/>
</beans>
文件吉他:
package com.springinaction.springidol;
public class Guitar implements Instrument {
@Override
public void play() {
System.out.println("Guitar playing");
}
}
文件乐器演奏家:
package com.springinaction.springidol;
public class Instrumentalist implements Performer {
private String song;
private Instrument instrument;
public Instrumentalist(){}
@Override
public void perform() throws Exception {
System.out.println("Playing "+song + " : ");
instrument.play();
}
public String getSong() {
return song;
}
public void setSong(String song) {
this.song = song;
}
public String screamSong(){
return song;
}
public void setInstrument(Instrument instrument) {
this.instrument = instrument;
}
}
文件受众(方面):
package com.springinaction.springidol;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
@Aspect
public class Audience {
@Pointcut("execution(* com.springinaction.springidol.Performer.perform(..))")
public void performance(){}
@Before("performance()")
public void takeSeats(){
System.out.println("The audience is takig their seats");
}
@Before("performance()")
public void turnOffCellPhones(){
System.out.println("The audience is turning off their cellphones");
}
@AfterReturning("performance()")
public void applaud(){
System.out.println("CLAP CLAP CLAP CLAP CLAP");
}
@AfterThrowing("performance()")
public void demandRefund(){
System.out.println("Boo! We want our money back");
}
@Around("performance()")
public void watchPerformance(ProceedingJoinPoint joinpoint){
try {
System.out.println("Theaudienceistakingtheirseats.");
System.out.println("Theaudienceisturningofftheircellphones");
long start=System.currentTimeMillis();
joinpoint.proceed();
long end=System.currentTimeMillis();
System.out.println("CLAP CLAP CLAP CLAP CLAP");
System.out.println("Theperformancetook"+(end-start)
+ "milliseconds.");
} catch(Throwable t){
System.out.println("Boo!Wewantourmoneyback!");
}
}
}
主文件:
package com.springinaction.springidol;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class SpringIdolMain {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("springIdolBeansAnnotation.xml");
Performer performer = (Performer) ctx.getBean("kenny2");
try {
performer.perform();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
最佳答案
是的,可能是因为旧 jar 。正如我假设您使用 spring 3.x jar 和 confiduration 一样。尝试使用最新的 jar
几天前我遇到了类似的问题,org.springframework.beans.factory.BeanCreationException: Error creating bean
在我的例子中,这是旧 jar 的问题 My issue
您能否尝试使用最新的 jars 运行您的应用:
aopalliance-1.0.jar
asm-3.3.1.jar
aspectj-1.7.1.jar
aspectjrt-1.7.0.jar
aspectjweaver-1.7.0.jar
cglib-2.2.2.jar
关于java - 嵌套异常是 java.lang.IllegalArgumentException: error at::0 cannot find referenced pointcut,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12502498/
这是方面类 public class TransactionAspect { public void beforeAnything() throws IOException{
我真的很悬。 此代码工作正常: @Before("execution(* *.runi(..))") public void perform() { sysout("hello"); }
我有这个切入点 @Pointcut("execution(@com.foo.bar.aspect.annotation.MyAnnotation* * (..))" + "&& @
背景: 我正在使用 Spring MVC 开发一个 Web 应用程序。 我想创建一个在 POST 请求上执行而不是在 GET 请求上执行的切面,因为我想注入(inject)阻止在 HTML 渲染完成之
我知道已经快周末了,但仍然值得尝试:) 我需要使用多个事务管理器,因此对我来说使用声明式事务管理而不是使用 tx:annotation-driven 是有意义的。但是,我在各种包中都有服务类,并且以下
如何为采用任意数量的参数(实现可序列化或原始类型)的方法编写切入点? 例如切入点应匹配: methodA(String str, int i) methodB(String str, String s
我正在尝试创建一个注释来记录带注释的类中的所有方法,但是我的切入点有问题,它没有应用(AspectJ 版本 1.7.4,aspectj-maven-plugin 版本 1.7)。 (advice de
自从使用 AspectJ 风格切面配置,使得 spring 的切面配置大大简化,但是 AspectJ 是另外一个开源项目,其规则表达式的语法也稍稍有些怪异。 下面给出一些常见示例的写法,例如,下面
我是 AOP 的新手。我在 AOP 的帮助下制作了一个通用的日志记录 API,其中定义了建议。 import org.apache.commons.logging.Log; import org.ap
我在 Spring 中学习 AOP 概念。我现在很清楚 @Before 的用法和 @After注释并开始将其用于时间捕获目的。 这几乎满足了我所有与 AOP 相关的需求。想知道那是什么@pointcu
我是 Spring AOP 的新手,我需要一些帮助 我有 MultiActionController,这是基于注释的。 我在 Spring 配置文件中为方法和 Advisor 定义了切入点。 我正在从
我想在调用另一个类的特定方法时触发一个方法,这就是我考虑使用@Pointcut的原因。 下面的代码与我正在编写的代码几乎相同,我不知道还需要添加什么。 public class OrgManagerI
我正在学习面向方面的编程概念和 Spring AOP。我无法理解切入点和连接点之间的区别——它们对我来说似乎都是一样的。切入点是您应用建议的地方,而连接点也是我们可以应用建议的地方。那有什么区别呢?
我正在尝试跟踪在 ServiceMix 3.2 上运行的应用程序的执行,该应用程序在后台使用 spring 2.5。我正在使用 CGLIB(建议类,而不是接口(interface)),我想使用切入点直
我的 Spring Web 模型- View - Controller (MVC) 框架中有这个类。我正在使用面向方面的编程(AOP),这是一种编程范例,旨在通过允许分离横切关注点来提高模块化性。这个
我正在学习 SpringAOP,在运行基本程序时,我观察到来自 eclipse(当然是编译器)的奇怪行为。 当我练习 @Pointcut 注释时,我错误地在 Pointcut 表达式中添加了另一个括号
我分配到的项目使用 xml 文件来创建 aop 配置。 第 1 部分: 我的xml文件中配置的aop是: 有人可以解释一下这里正在做什么吗?我知道切入点的作用,但在这
所以我正在尝试使用 Python Cubes Framework 实现一些 BI,但我遇到了一些问题。 基本上我正在尝试做一个“简单的”PointCut/切片和骰子,但我没有任何运气。我在 PostG
我必须检测字段值的变化。我想将以前的值与新值进行比较。我不知道字段名称或其类型。 (更多背景 here 。)对于给定类的示例: package eu.zacheusz.aspectjtries; @e
考虑我已经定义了以下方面: @Aspect public class SampleAspect { @Around(value="@annotation(sample.SampleAnnota
我是一名优秀的程序员,十分优秀!