当我尝试在春天自动连接aspectj时,我收到以下错误
org.xml.sax.SAXParseException: The prefix "aop" for element "aop:aspectj-autoproxy" is not bound.
Run Code Online (Sandbox Code Playgroud)
我的appContext.xml条目看起来像......
<aop:aspectj-autoproxy/>
<bean id="helloFromAspectJ" class="com.cvs.esps.aspect.logging.TestAspect"/>
Run Code Online (Sandbox Code Playgroud)
.....
一些帮助我怎么能删除这个错误..不幸的是网站http://forum.springsource.org被网络防火墙阻止..任何帮助快速将受到高度赞赏.
这是我得到的,如果我添加线
<bean id="loggerProxy" class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator" />
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.cxf.bus.spring.BusApplicationListener' defined in class path resource [META-INF/cxf/cxf.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cxf': Cannot create inner bean 'cxf:logging#d306dd' of type [org.apache.cxf.feature.LoggingFeature] while setting bean property 'features' with key [0]; …Run Code Online (Sandbox Code Playgroud) 使用Java 7的aspectj插件有哪些适当的配置/版本/插件版本?
我正在尝试从Java 6升级到Java 7,而aspectj编译器似乎没有编译Java 7.我在Aspectj插件和maven编译器插件的插件配置中将java源和目标版本指定为1.7.我在我的代码中引入了Java7特定的语法,添加了几个语言功能,如switch in switch和diamond operator.在构建期间,我从aspectj获取有关Java7语法的错误.事情出错的第一个迹象是:
[INFO] --- aspectj-maven-plugin:1.4:compile (default) @ site ---
[ERROR] Cannot switch on a value of type String. Only int values or enum constants are permitted
[ERROR] Cannot instantiate the type HashSet<?>
[ERROR] Syntax error on token "<", ? expected after this token
Run Code Online (Sandbox Code Playgroud)
如果我从aspectj maven插件中删除执行部分,因此它不运行,并使用mvn clean install,新代码编译正常.所以我认为这是与aspectj错误配置的东西.这是我的插件配置:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java-version>1.7</java-version>
<org.aspectj-version>1.6.11</org.aspectj-version>
</properties>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${org.aspectj-version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${org.aspectj-version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal> …Run Code Online (Sandbox Code Playgroud) 我刚刚处理了一个日志不好或没有日志的旧应用程序.它没有实现Spring框架.
没有Spring可以实现AspectJ日志记录功能吗?
如果是,请向我推荐一些好的教程.
我正在使用Spring框架(4.0.5)和AspectJ进行AOP Logging开发一个java(JDK1.6)应用程序.
我的Aspect类工作正常,但我无法为构造函数对象创建切入点.
这是我的目标:
@Controller
public class ApplicationController {
public ApplicationController(String myString, MyObject myObject) {
...
}
...
..
.
}
Run Code Online (Sandbox Code Playgroud)
这是我的Aspect类:
@Aspect
@Component
public class CommonLogAspect implements ILogAspect {
Logger log = Logger.getLogger(CommonLogAspect.class);
// @Before("execution(my.package.Class.new(..)))
@Before("execution(* *.new(..))")
public void constructorAnnotatedWithInject() {
log.info("CONSTRUCTOR");
}
}
Run Code Online (Sandbox Code Playgroud)
如何为构造函数对象创建切入点?
谢谢
我在Tomcat 6 webapp中使用Spring进行加载时编织时遇到了一些问题.我只想将它用于事务(因此自我调用遵循事务注释,而不是AOP代理).似乎正在加载织布工,但我的注释类实际上并没有被编织.当我单步执行代码时,我在SQL日志中看不到任何事务边界,正如我在常规AOP代理配置中看到的那样.这是我的设置:
在server.xml中:
<Context path="/api" allowLinking="true" reloadable="false" docBase="/usr/local/apache-tomcat-6.0.18/webapps/API/ROOT" workDir="/usr/local/apache-tomcat-6.0.18/webapps/API/ROOT/work">
<Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/>
</Context>
Run Code Online (Sandbox Code Playgroud)
我有tom-tomcat-weaver.jar tomcat/lib目录,以及我的Tomcat类路径上的以下jar:
tomcat/webapps/API/ROOT/WEB-INF/lib/aspectjweaver.jar tomcat/webapps/API/ROOT/WEB-INF/lib/spring-aspects.jar
这是在bean配置文件中定义带注释的服务类:
<tx:annotation-driven transaction-manager="txManager" mode="aspectj"/>
Run Code Online (Sandbox Code Playgroud)
在我的上下文中的许多其他bean配置文件之一:
<aop:aspectj-autoproxy>
<aop:include name="methodTimer"/>
</aop:aspectj-autoproxy>
<context:load-time-weaver aspectj-weaving="on"/>
<context:annotation-config />
<bean name="methodTimer" class="tv.current.web.aop.MethodTimer" />
Run Code Online (Sandbox Code Playgroud)
我希望MethodTimer使用常规AOP代理,而不是LTW - LTW应该仅适用于@Transactional注释.如下所述:http://static.springsource.org/spring/docs/2.5.x/reference/aop.html#aop-aj-configure.如果我注释掉<aop:aspectj-autoproxy>元素,我不会得到任何我看到的编织信息日志消息.说到这里,他们在这里; 你可以看到方面正在加载,但实际上没有任何东西被编织:
Aug 28, 2009 6:34:42 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
[TomcatInstrumentableClassLoader@34fe7e0e] info AspectJ Weaver Version 1.6.5 built on Thursday Jun 18, 2009 at 03:42:32 GMT
[TomcatInstrumentableClassLoader@34fe7e0e] info register classloader org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader@34fe7e0e
[TomcatInstrumentableClassLoader@34fe7e0e] info using configuration …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用@Controller,基于注释的方法设置Spring 3 Web MVC项目.
package my.package
@Controller
@RequestMapping("/admin/*")
public class AdminMultiActionController {
@RequestMapping(value = "admin.htm", method = RequestMethod.GET)
public String showAdminSection() {
return "admin";
}
Run Code Online (Sandbox Code Playgroud)
我的dispatcher-servlet具有以下Controller处理程序:
<context:component-scan base-package="my.package" />
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
Run Code Online (Sandbox Code Playgroud)
使用提供的maven工件,webapp运行良好:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.0.2.RELEASE</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
现在我想添加@AspectJ AOP.我得到了libs:
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.6.9</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.6.9</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
添加到我的applicationContext.xml:
<aop:aspectj-autoproxy/>
Run Code Online (Sandbox Code Playgroud)
确保在applicationContext.xml中创建相关的bean:
<bean id="securityInterceptor" class="my.package.service.SecurityInterceptor"/>
Run Code Online (Sandbox Code Playgroud)
并开始充实@Aspect:
package my.package.service
@Aspect
public class SecurityInterceptor {
@Pointcut("execution(* showAdminSection(..))")// the pointcut expression
private void foo() {
System.out.println("fooo");
}// the pointcut …Run Code Online (Sandbox Code Playgroud) 我有一个基于Spring 3的java应用程序构建.这个项目有另一个jar作为依赖.
这个依赖包含一个@org.aspectj.lang.annotation.Aspect类(比如说com.aspectprovider.aspects.MyAspect).有一个@Before建议从实现接口的类编织方法Foo.就像是:
@Before("execution(* com.project.Foo.save(..))")
Run Code Online (Sandbox Code Playgroud)
该Foo接口可以是"项目"内或另一罐子.这个例子没关系.
我的项目包含实现的类Foo.当然,那些是我希望它被编织的类.
我的Spring应用程序上下文配置文件(applicationContext.xml)包含以下行:
<aop:aspectj-autoproxy />
Run Code Online (Sandbox Code Playgroud)
我还将方面声明为bean,并注入一些属性:
<bean id="myAspect" class="com.aspectprovider.aspects.MyAspect"
factory-method="aspectOf" >
<property name="someproperty" value="somevalue" />
</bean>
Run Code Online (Sandbox Code Playgroud)
通过日志记录,我可以看到MyAspect实例化并注入了属性.但是方法保存没有被截获.这就是问题.
如果我将方面类从jar复制到具有Spring的应用程序,它可以工作.当这些方面包含在外部jar中时,方法save不会被截获.有线索吗?
编辑:我如何调用Foo的保存方法:
//in a JSF managed bean
@Inject
private Foo myFoo; //there's a implementation of Foo in a package that spring is looking at. So it is injected correctly.
public String someAction() {
myFoo.save("something"); //the @Before advice is only called if the …Run Code Online (Sandbox Code Playgroud) 我一直在为我的创业公司广泛使用Java + AspectJ.我想切换到Scala,但我有一个共同的设计模式,我不确定完全是在Scala中实现的最佳方式.
我们的大量应用程序使用注释作为标记使用AspectJ切入点.这与Python的装饰者非常相似,并在此博客.
我曾尝试在Scala中使用此技术但遇到了AspectJ + Scala的问题.即使我确实让它工作,似乎unScala喜欢.
我已经看到一些项目做了一些名称封闭魔术(我认为这就是他们正在做的事情).
替换@Transaction的示例:
transaction {
// code in here.
}
Run Code Online (Sandbox Code Playgroud)
我不得不说,虽然我更喜欢注释,因为它似乎更具说明性. 什么是声明式"装饰"代码块的Scala方式?
我是AspectJ的初学者,所以请指导我按照以下方法解决发生的问题.
@Aspect
public class TestAop {
@Pointcut("execution(public * com.packg.foo.ClassOne.*(..))")
public void fooPoint()
@Pointcut("execution(public * com.packg.cat.ClassTwo.*(..))")
public void catPoint()
@Pointcut("execution(public * com.packg.roo.ClassThree.*(..))")
public void rooPoint()
@Around("fooPoint() || catPoint() || rooPoint()")
public Object myAdvice(ProceedingJoinPoint joinPoint) {
//do something like joint proceed and all
}
Run Code Online (Sandbox Code Playgroud)
什么时候不工作?如果我将所有三个切入点与OR组合在一起.
什么时候工作?如果我只保留两个切入点就可以了.
我违反了@around建议的任何规则.是否可以有多个执行/切入点?
希望得到答案......
使用maven和纯java项目,我能够使用codehaus的aspectj-maven-plugin来编织(编译时)方面(从我构建的库)到我的带注释的类.
我想用android项目(gradle build)做同样的事情,但似乎找不到太多的文档.
我已经找到了Android的贴切项目在这里,但不能换我围绕着如何用AspectJ织使用它的头.
任何帮助赞赏.