Time: 2024-05-16 Thursday 11:02:01
Author: Jackasher
Spring类注解配置文件
在config的类标Config注解,组件扫描时会获取
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| package org.example.service;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.EnableAspectJAutoProxy;
@Configuration @ComponentScan({"org.example.service"}) @EnableAspectJAutoProxy(proxyTargetClass = true) public class SpringConfig { }
|
这是注解类作为参数
1 2 3 4 5 6
| @Test public void annotationTest(){ ApplicationContext applicationContext = new AnnotationConfigApplicationContext(SpringConfig.class); UserService userService = applicationContext.getBean("userService", UserService.class); userService.login(); }
|