##常用依赖
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.1.9.RELEASE</version>
</dependency>
##注解说明
@Autowired:通过类型自动装配,如果存在多个bean对象,@Autowired不能自动装配,则需要通过@Qualifier(value=" ")指定自动装配的对象
@Resource是java自带的注解,通过name自动装配
@Nullable标明该字段可以为null
在类上标注@Component自动生成Bean,等价于<bean id= …class = … />,在属性或者set方法标注@value可以为属性赋值
@Component有几个衍生注解,在web开发中按照mvc三层架构分层
dao [@Repository]
service [@Service]
controller[@Controller]
##作用域说明
@Scope(singleton)
##使用JavaConfig实现配置类
@Configuration
public class UserConfig {
//注册一个bean,相当于一个bean标签
//方法的名字相当于bean标签中的id,方法的返回值类型相当于bean标签中的class
//如果完全使用配置类来做,只能通过AnnotationConfig来获取上下文
// ApplicationContext context = new AnnotationConfigApplicationContext(UserConfig.class);
@Bean
public User getUser(){
return new User();
}
}