我试图使用AOP在带注释的控制器之后进行一些处理.一切都在运行,没有错误,但建议没有被执行.
这是控制器代码:
@Controller
public class HomeController {
@RequestMapping("/home.fo")
public String home(ModelMap model) {
model = new ModelMap();
return "home";
}
}
Run Code Online (Sandbox Code Playgroud)
和application-config中的设置
<aop:aspectj-autoproxy/>
<bean id="testAdvice" class="com.test.TestAdvice">
</bean>
<bean id="testAdvisor"
class="org.springframework.aop.aspectj.AspectJExpressionPointcutAdvisor">
<property name="advice" ref="testAdvice" />
<property name="expression" value="execution(* *.home(..))" />
</bean>
Run Code Online (Sandbox Code Playgroud)
和实际的建议
public class TestAdvice implements AfterReturningAdvice {
protected final Log logger = LogFactory.getLog(getClass());
public void afterReturning(Object returnValue, Method method, Object[] args,
Object target) throws Throwable {
logger.info("Called after returning advice!");
}
}
Run Code Online (Sandbox Code Playgroud)
甚至可以在带注释的控制器上提供建议吗?我使用的是Spring 2.5.
我有一个目前适用于java 6和编译时编织的项目.我们使用以下pom来启用spring方面和我们自己的方面:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<source>1.6</source>
<target>1.6</target>
<Xlint>ignore</Xlint>
<complianceLevel>1.6</complianceLevel>
<encoding>UTF-8</encoding>
<verbose>false</verbose>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
我已尝试过各种配置,但无法使其与java 7一起使用.如果有人可以共享工作pom或引导它会很棒.
我使用Spring 2.5和Hibernate JPA实现Java和"容器"管理事务.
我有一个"用户提交后"方法,它在后台更新数据,无论是异常ConcurrencyFailureException还是StaleObjectStateException异常都需要提交,因为它永远不会显示给客户端.换句话说,需要将乐观锁定变为悲观.(如果方法执行需要更长的时间并且有人在其他事务中更改了数据,则可能发生)
我读了很多关于幂等的东西,如果异常搜索DEFAULT_MAX_RETRIES或6.2.7则重试.示例或第14.5章.重试.我也在这里和这里找到了stackoverflow .
我试过这个:
public aspect RetryOnConcurrencyExceptionAspect {
private static final int DEFAULT_MAX_RETRIES = 20;
private int maxRetries = DEFAULT_MAX_RETRIES;
Object around(): execution( * * (..) ) && @annotation(RetryOnConcurrencyException) && @annotation(Transactional) {
int numAttempts = 0;
RuntimeException failureException = null;
do {
numAttempts++;
try {
return proceed();
}
catch( OptimisticLockingFailureException ex ) {
failureException = ex;
}
catch(ConcurrencyFailureException ex) { …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用java 6.0将aspectj添加到maven项目中.浏览我发现2个maven插件,其中没有一个按我期望的方式工作.
第一个http://mojo.codehaus.org/aspectj-maven-plugin最初没有通过netbeans工作,因为我无法获得编译5.0或更高版本的源代码(它抱怨注释等)从命令尝试后工作和比较执行的命令的行似乎它的mavens安装目标与插件和java 5+代码不兼容,而编译目标工作正常.虽然有可能解决这个问题,但这很烦人并且让我想到了一个问题:aspectj-maven-plugin还在开发中吗?我还应该用吗?
第二个是apaches自己的,它似乎更活跃,更有可能工作.但是我找不到任何完整的例子,我无法运行它.我一直从maven得到一个例外:
java.lang.IllegalStateException: The plugin descriptor for the plugin Plugin [maven:maven-aspectj-plugin] was not found. Please verify that the plugin JAR /home/kristofer/.m2/repository/maven/maven-aspectj-plugin/4.0/maven-aspectj-plugin-4.0.jar is intact.
Run Code Online (Sandbox Code Playgroud)
jar文件是完整的,并且我使用的插件版本也无关紧要,它总是抛出相同的异常.关于问题可能是什么的任何想法?
简而言之,哪个插件以及我应该如何使用它?
谢谢
我正在使用@AspectJ样式来编写方面,以处理我们的应用程序中的日志记录.基本上我有一个切入点设置如下:
@Pointcut("call(public * com.example..*(..))")
public void logging() {}
Run Code Online (Sandbox Code Playgroud)
然后像之前和之后的建议一样:
@Before("logging()")
public void entering() {...}
...
@After("logging()")
public void exiting() {...}
Run Code Online (Sandbox Code Playgroud)
我想以下列格式创建这些方法的日志:
logger.trace("ENTERING/EXITING [" className + "." + methodName "()]");
Run Code Online (Sandbox Code Playgroud)
问题是我不知道如何获取类和方法名称的引用.我试过了:
joinPoint.getThis().getClass()
Run Code Online (Sandbox Code Playgroud)
但这似乎返回了调用者的类名.
class A {
public void a() {
B.b();
}
}
class B {
public void b() {
...
}
}
Run Code Online (Sandbox Code Playgroud)
会导致以下日志
ENTERING [A.b()]
Run Code Online (Sandbox Code Playgroud)
有人可以提供一些关于如何获得实际的连接点类和方法名称的帮助
将 Java 版本更改为 17 后,我无法构建 Gradle 项目。
我正在使用 Gradle 7.3.1 版本,并且 Gradle 属性中有以下行:
org.gradle.jvmargs=-Dfile.encoding=UTF-8 -Xms1g -Xmx4g -XX:+UseG1GC -XX:+CMSClassUnloadingEnabled
Run Code Online (Sandbox Code Playgroud)
然后我得到以下错误
Unrecognized VM option 'CMSClassUnloadingEnabled'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Run Code Online (Sandbox Code Playgroud)
如果我删除-XX:+CMSClassUnloadingEnabled然后我收到此错误:
Unable to make field private int java.lang.reflect.Field.modifiers accessible: module java.base does not "opens java.lang.reflect" to unnamed module @1b9ee3e0
Run Code Online (Sandbox Code Playgroud) 我需要在maven项目中使用aspectj.我为eclipse(m2e)安装了maven插件,maven aspectj插件以及Eclipse的AJDT.所以现在,当我打开一个新项目时,我有"Maven项目"和"AspectJ项目".我怎样才能创建一个Maven AspectJ项目的新项目?我没有找到任何参考,所以你是我唯一的希望.谢谢
我是新来的,在我的办公室里.所以我没有指导.
我需要AOP使用the 来实现日志记录log4j.
我在没有AOP基本spring MVC示例的情况下实现了日志记录?
还AOP使用了aspectJ没有记录的小样本(只是制作了Sysout)?
我不知道如何整合它?
任何人都可以给我一个启动想法吗?
很好的答案肯定赞赏...
谁能告诉我Joinpoint和 之间有什么区别 Proceedingjoinpoint?
何时使用Joinpoint和 Proceedingjoinpoint方面类的方法?
我用过JoinPoint我AspectJ class喜欢的,
@Pointcut("execution(* com.pointel.aop.test1.AopTest.beforeAspect(..))")
public void adviceChild(){}
@Before("adviceChild()")
public void beforeAdvicing(JoinPoint joinPoint /*,ProceedingJoinPoint pjp - used refer book marks of AOP*/){
//Used to get the parameters of the method !
Object[] arguments = joinPoint.getArgs();
for (Object object : arguments) {
System.out.println("List of parameters : " + object);
}
System.out.println("Method name : " + joinPoint.getSignature().getName());
log.info("beforeAdvicing...........****************...........");
log.info("Method name : " + joinPoint.getSignature().getName());
System.out.println("************************");
}
Run Code Online (Sandbox Code Playgroud)
但我在其他资源中看到的一些是,
@Around("execution(* …Run Code Online (Sandbox Code Playgroud) 我试图在IntelliJ中使用插件com.android.tools.build:gradle:3.0.0-alpha4.但我有错误
Error:This Gradle plugin requires Studio 3.0 minimum
Run Code Online (Sandbox Code Playgroud)
android gradle插件版本2.3.3支持Intellij.
我需要IntelliJ,因为我想在IDE中使用AspectJ + Java 8.Android Studio IDE尚不支持AspectJ,只支持gradle插件.
是否可以使用新版Android Gradle Plugin 3.0.0与IntelliJ,而不是Android Studio?
谢谢.