ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
之前依然会应用到配置文件`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); } ```