- @Test(Junit包):可以在不调用main方法直接测试。
- @SuppressWarnings(“all”):压制代码中所有的不规则的命名,更美观。
- @Autowired通过类型 名字自动装配(如果@Autowired不能唯一自动装配上属性,则需要使用@Qualifier(value = “xxx”))
- @Nullable:字段标注了这个注解,说明这个字段可以为null
- @Resource:通过名字 类型。
- @Component : 组件,放在类上,说明这个类被Spring管理了,就是bean!
Component的衍生注解
- @Repository (dao层)
- @Service(service层)
- @Controller(controller层)
配合@ComponentScan(“com.chang.domain”)使用! - @Scope:bean的作用域,值为prototype或者singleton。
- @Value:注入bean的值。
- @Configuration
- @Bean
@Configuration
@ComponentScan("com.chang.domain")
public class ChangConfig {
@Bean
public User getUser(){
return new User();
}
}