企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
之前依然会应用到配置文件`ApplicationContext.xml`,这个配置文件也可以使用注解来代替。如下封装一个配置类来代替该配置文件。 (1)封装配置类。 ```java @Configuration //当前类具有与ApplicationContext.xml配置文件同等功能 @ComponentScan(basePackages = {"com.learn.spring06"}) //包扫描,从当前包开始往下层扫描 @EnableAspectJAutoProxy(proxyTargetClass = true) //开启AspectJ代理 public class CustomeConfiguration { } ``` (2)调用。 ```java @Test public void completelyAnno() throws Exception { ApplicationContext context = new AnnotationConfigApplicationContext(CustomeConfiguration .class); StudentService studentService = (StudentService) context.getBean("studentService"); studentService.add(10, 20); } ```