文章目录
注解实现自动装配
@Autowire注解
@Qualifier注解
@Resource注解
@Component
@Scope
@ComponentScan
@Bean
@Configuration
@Value
P命名空间注入
C命名空间注入
Spring开发包名解释
Java方式配置
@Configuration
@ComponentScan("com.wei.pojo")
@Import(WeiConfig2.class)
public class WeiConfig {
@Bean
public User getUser(){
return new User();
}
}
public class MyTest {
public static void main(String[] args) {
ApplicationContext context = new AnnotationConfigApplicationContext(WeiConfig.class);
User getUser = (User) context.getBean("getUser");
System.out.println(getUser.getName());
}
}
