【发布时间】:2017-11-07 13:27:11
【问题描述】:
注释似乎没有影响。在此处添加了更多文本以满足编辑器,该站点需要一定的详细程度。
我的 Pom 条目
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
<exclusion>
<artifactId>jcl-over-slf4j</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
<exclusion>
<artifactId>jul-to-slf4j</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
<exclusion>
<artifactId>log4j-over-slf4j</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
<exclusion>
<artifactId>logback-classic</artifactId>
<groupId>ch.qos.logback</groupId>
</exclusion>
</exclusions>
</dependency>
在 applicationContext.xml 中(定义了其他 bean)
<bean id="myAspect" class="com.myapp.MyAspect" lazy-init="false"/>
我的一面
package com.myapp;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
@Aspect
@Component
public class MyAspect {
@Around("@annotation(LogArguments)")
public Object logArguments(ProceedingJoinPoint joinPoint) throws Throwable {
System.err.println("put breakpoint here, never stops here");
return joinPoint.proceed();
}
}
注释
package com.myapp;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface LogArguments {
}
此代码在我的控制器内部
@RequestMapping(value = "/search", method = RequestMethod.POST)
@LogArguments
public @ResponseBody SearchResult performSearch(@RequestBody SearchForm
searchForm, HttpServletRequest request) throws Exception {
LOG.debug("If I put a break point here it stops here, but not in the aspects code:" + searchForm);
}
【问题讨论】:
标签: java spring annotations aop