2019/11/16 学习笔记
2019/11/16 学习笔记
navcat安装和**
https://blog.****.net/qq_40752902/article/details/90442881
根据这个链接一步步进行 应该不会有大问题
spring学习
@注解:省去了写xml配置文件的麻烦
IOC容器:一个大型的map,需要什么就把什么注入进去,比如把bean注入进去,就用@Bean。
@Configuration :定义配置类 一般也在这个里面注入Bean
通过这个 ApplicationContext context = new AnnotationConfigApplicationContext(XXXConfiguration.class);来获取配置类,这句话也是启动ioc容器
@Bean:Bean注解,用于注入Bean,注入的id默认为方法名,也可以使用@Bean(“xxx”)来指定id
如:@Bean
public Person person(){
System.out.println(“我要被创建了”);
return new Person(“jame”,20);
}
@ComponentScan:默认扫描包下所有配置类 可以使用@ComponentScans 来增加多个选择效果
指定扫描的范围,@ComponentScan(value=“com.xxx.xxx”)
excludeFilters :除去某个配置类
includeFilters:包含某个配置类, 要生效的话,需要把useDefaultFilters = false
用法:@ComponentScan(value=“XXX”,includeFilters={
@Filter(type = FilterType.CUSTOM,classes = {TestTypeFilter.class})
},useDefaultFilters = false)
ANNOTATION:包含/除去某类注解
FilterType.ANNOTATION,classes = {Controller.class}
ASSIGNABLE_TYPE:包含/除去某类类名FilterType.ASSIGNABLE_TYPE,classes = {OrderController.class}
CUSTOM:用户自定义
@Scope:
@Scope(“prototype”)
@Bean
public Person person(){
return new Person(“jame”,20);
}
prototype:多实例,IOC容器启动时并不会去调用方法创建对象,而是每次获取的时候才会调用方法创建对象
singleton:单实例,IOC容器启动时会去调用方法创建对象,以后每次获取的就是直接从容器中的同一个
request:主要针对web应用,递交一次请求创建一个实例
session:同一个session创建一个实例
@Lazy:懒加载:主要针对单实例(默认容器启动时创建对象) 容器启动时 new AnnotationConfigApplicationContext(XXXConfiguration.class)不创建对象,仅当第一次使用(获取 getBean())bean的时候才创建被初始化