依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
注解
第一步:
我们需要在Spring Boot的启动类,或者在我们自己配置的配置类上面加上AspectJ的配置
启动类上加注解:
@Configuration
@EnableAspectJAutoProxy
@EnableTransactionManagement
@EnableNeo4jRepositories(basePackages= GavGraphConstants.BASE_PACKAGE)
@SpringBootApplication(scanBasePackages = GavGraphConstants.BASE_PACKAGE)
public class GavgraphApplication {
private static Logger logger = LogManager.getLogger(GavgraphApplication.class.getName());
private static final Marker SERVER_START_MARKER = MarkerManager.getMarker("SERVER_START");
public static void main(String[] args) {
logger.info(SERVER_START_MARKER,"===========GAVGraphApplication is starting!===========");
SpringApplication.run(GavgraphApplication.class, args);
logger.info(SERVER_START_MARKER,"=============GAVGraphApplication started!=============");
}
配置类上加注解:
@Configuration
@EnableAspectJAutoProxy
public class AppConfiguration{
}
第二步
创建具体的Aspect类,加上@Aspect注解
@Aspect
public class LoggingAspect {
}