(37)全注解式开发AOP

就是编写一个类,在这个类上面使用大量注解来代替spring的配置文件,spring配置文件消失了,如下:

java 复制代码
package com.powernode.spring6.service;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

@Configuration
@ComponentScan("com.powernode.spring6.service")
@EnableAspectJAutoProxy(proxyTargetClass = true)
public class Spring6Configuration {
}

测试程序也变化了:

java 复制代码
@Test
public void testAOPWithAllAnnotation(){
    ApplicationContext applicationContext = new AnnotationConfigApplicationContext(Spring6Configuration.class);
    OrderService orderService = applicationContext.getBean("orderService", OrderService.class);
    orderService.generate();
}

执行结果如下:

相关推荐
小碗羊肉几秒前
【从零开始学Java | 第三十二篇】方法引用(Method Reference)
java·开发语言
满满和米兜6 分钟前
【Java基础】- 集合-HashSet与TreeSet
java·开发语言·算法
网安INF18 分钟前
数据结构第二章复习:线性表
java·开发语言·数据结构
aq553560021 分钟前
Laravel10.X核心特性全解析
java·开发语言·spring boot·后端
锦瑟弦音37 分钟前
Java与SQL基础知识总结
java·开发语言
停水咋洗澡40 分钟前
Redis Sentinel高可用实战:主从自动故障转移
java·redis·sentinel
ch.ju43 分钟前
Java程序设计(第3版)第二章——引用数据类型:String
java
yaoxin5211231 小时前
376. Java IO API - 使用 Globbing 和自定义 Filter 过滤目录内容
java·开发语言·python
手握风云-1 小时前
JavaEE 初阶第三十一期:JVM,一次Full GC的架构级思考(下)
java·java-ee