ComponentS
can 和
ComponentS
cans 都是用来声明要扫描的包,
CompenentScan 每次可以写一个或多个包,比如:
@
ComponentS
can(value = {"service","dao"})
@
ComponentS
can("dao")
ComponentS
cans可以声明多个
ComponentS
can:
@
ComponentS
cans(value = {@
ComponentS
can("dao"),@
ComponentS
can("service")})
文章目录链接视频github老的方式注解@
ComponentS
can测试用例配置类启动类结果结果解析
ComponentS
can注解
ComponentS
can的excludeFilters配置类启动类结果结果解析
ComponentS
can的includeFilters配置类结果结果解析真正的配置正常xml配置配置类配置结果
ComponentS
cans配置类运行结果
https://www.bilibili.com/medialist/play/ml1022680573/p3
github
项目中
Spring
Boot会对哪些包自动执行扫描(Component Scan)?
如何利用
Spring
Boot定义扫描范围?
@Component and @
ComponentS
can 的
区别
1.@Component
@Component 被称为元注释,它是@Repository、@Service、@Controller、@Configuration的父类,理论上可以使用@C
@
ComponentS
can @Configuration @Conditional @Retention @Documented @Target @Inherited @Bean @Import等注解含义的总结和个人理解:
包扫描@
ComponentS
can+组件标注注解(@Controller/@Service/@Repository/@Component)一般作用与自己写的类。 includeFilters表示包扫描的条件,起到过滤的作用。默认@
ComponentS
can会扫描标注这四个注解,将标注这四个注解类的实例对象注入到
spring
ioc容器中。使用useDefaultFilt
虽然
Spring
的组件代码是轻量级的,但它的配置却是重量级的。一开
始,
Spring
用 XML 配置,而且是很多 XML 配
置。
Spring
2.5 引入了基于注解的组件扫描,这消除了大量针对应用
程序自身组件的显式 XML 配置。
Spring
3.0 引入
了基于
Java
的配置,这是一种类型安全的可重构配置方式,可以代
替 XML。
一 、注解列表
@
Spring
BootApplication: 包含了@
ComponentS
can、@Configuration和@EnableAutoConfiguration注解。其中@
ComponentS
can让
Spring
Boot扫描到Configuration类并把它加入到程序上下文。
@Configuration: 等同于
Spring
的XML配置文件;使用
Java
代码可以检查类型安全。
@EnableAutoConfiguration: 自动配置。
@
ComponentS
can: 组件扫描,可自动发现和配置一些Bean。
@Component: 可配合CommandLineRu
在火狐中显示可能会有问题,大家都是程序员,改个参数就好啦
注解包含: 拦截器 , 过滤器 , 序列化 , @After , @AfterReturning , @AfterThrowing , @annotation , @Around , @Aspect , @Autowired , @Bean , @Before , @Component , @
ComponentS
can , @
ComponentS
cans , @Configuration , @ConfigurationProperties , @Controller , @CrossOrigin , @EnableWebMvc , @GetMapping , @Import , @JsonDeserialize , @JsonIgnore , @JsonIgnoreProperties , @JsonIgnoreType , @JsonInclude , @JsonProperty , @JsonPropertyOrder , @JsonSerialize , @JsonSetter , @Lazy , @Order , @PathVariable , @Pointcut , @PostConstruct , @PostMapping , @PreDestroy , @Primary , @PropertySource , @Qualifier , @Repository , @RequestBody , @RequestMapping , @RequestParam , @Resource , @ResponseBody , @RestController , @Scope , @Service , @Validated , @Value , @WebFilter , @WebInitParam , @WebListener
先说下就个注解的作用:
@
ComponentS
can: 指定包路径扫描,把@Controller、@Service、@Repository,@Component标注的类,实例化到
spring
容器中
@Filter: 是@
ComponentS
can注解类中的子注解(内部注解),可以指定一些过滤规则
FilterType.ANNOTATION:按照注解注入...
配置视图控制器
package com.apress.pro
spring
mvc.bookstore.web.config;
import org.
spring
framework.web.servlet.config.annotation.ViewControllerRegistry;
@
ComponentS
can和@MapperScan是
Spring
和MyBatis中的注解,用于扫描指定的包并将其中的组件或Mapper类注册到
Spring
应用程序上下文或MyBatis配置中。
@
ComponentS
can注解扫描指定的包,并自动将标记有注解@Component、@Service、@Controller等的类注册为
Spring
应用程序上下文中的Bean。它可以指定要扫描的基础包,也可以使用excludeFilters和includeFilters属性进行过滤。
@MapperScan注解扫描指定的包,并将标记有@Mapper注解的类注册为MyBatis中的Mapper。它可以指定要扫描的基础包,也可以使用annotationClass属性指定要扫描的注解类。在MyBatis的配置文件中,还需要配置Mapper接口的扫描路径。