2020年6月29日
配置类 注解@Configruation
-
注解扫描,通过注解@ComponentScans,扫描指定的包.
package com.wzl.yanyan.spring01; import com.wzl.yanyan.Person; import com.wzl.yanyan.spring01.filter.MyFilterType; import com.wzl.yanyan.spring01.service.SpringService; import org.springframework.context.annotation.*; import org.springframework.stereotype.Controller; @Configuration //@ComponentScan(value = "com.wzl.yanyan", // excludeFilters ={@ComponentScan.Filter(type = FilterType.ANNOTATION,classes = {Controller.class})} ) // @ComponentScans(value = { @ComponentScan(value = "com.wzl.yanyan", includeFilters ={ // @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = {Controller.class}), // @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,classes = {SpringService.class})} , @ComponentScan.Filter(type = FilterType.CUSTOM,value = {MyFilterType.class})}, useDefaultFilters = false)}) // 查看注解,以及用法 // 使用 includeFilters,或者 excludeFilters, public class MainConfig { /** * 默认方法名称作为ID * @return Person */ @Bean("persons") public Person personConfig(){ return new Person("config",21); } } bean的作用域,如果默认是单例的.会直接创建Bean
懒加载是针对 singleton