福利发送:
1:你想彻底搞明白SpringSecurity么?你想对SpringSecurity6进行源码级别的学习么?
2:你想彻底掌握Spring的应用和源码,在面试的时候吊打面试官么?
那欢迎你加入suns 孙哥的企鹅QQ 3群:583783824
在这里你可以找到志同道合的朋友,还有大神孙哥作为你的领路人。在这里,不仅仅是SpringSecurity更让你在Mybatis、Netty、Rpc、Dubbo、SpringCloud、Docker和k8s....等等技术领域发生翻天覆地的变化。
以上所有,在群里都有我们免费的视频和笔记资料呦~~~
欢迎进群领取,期待你的加入!
文章目录
5:SpringBoot...Configuration详解
问题引入
1:问题阐述
为什么在引入SpringSecurity之后所有的请求都需要先做登录认证才可以进行访问呢?
2:问题分析
分析清楚这个问题之前,我们先从自动装配开始研究。
一:从SpringBoot的自动装配
1:@SpringBootApplication介绍
这个注解的作用就是标志这个类是SpringBootApplication的启动类。
@SpringBootApplication
public class BigtreeApplication {
public static void main(String[] args) {
SpringApplication.run(BigtreeApplication.class, args);
}
}
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(
excludeFilters = {@Filter(
type = FilterType.CUSTOM,
classes = {TypeExcludeFilter.class}
), @Filter(
type = FilterType.CUSTOM,
classes = {AutoConfigurationExcludeFilter.class}
)}
)
public @interface SpringBootApplication {
@AliasFor(annotation = EnableAutoConfiguration.class)
Class<?>[] exclude() default {};
@AliasFor(annotation = EnableAutoConfiguration.class)
String[] excludeName() default {};
@AliasFor(annotation = ComponentScan.class,attribute = "basePackages")
String[] scanBasePackages() default {};
@AliasFor(annotation = ComponentScan.class, attribute = "basePackageClasses")
Class<?>[] scanBasePackageClasses() default {};
@AliasFor(annotation = ComponentScan.class,attribute = "nameGenerator")
Class<? extends BeanNameGenerator> nameGenerator() default BeanNameGenerator.class;
@AliasFor( annotation = Configuration.class)
boolean proxyBeanMethods() default true;
}
这个注解是一个复合注解@SpringBootConfiguration这个注解的作用带表了这当前这个类是一个SpringBoot配置类,自动交给SpringIOC容器进行管理。
第二个注解是ComponentScan这个注解的作用是定义Spring的扫描路径的。通畅对应我们自己定义的组件例如:Controller,Service,Dao这些组件。
第三个注解是:@EnableAutoConfiguration这个注解是SpringBoot自动装配的关键注解,这个注解包含两个核心注解
第一个注解是:@Import({AutoConfigurationImportSelector.class})这个注解的作用就是在导入当前类的同时顺便导入AutoConfigurationImportSelector这个类也加载进来。
2:自动装配的核心方法
org.springframework.boot.autoconfigure.AutoConfigurationImportSelector#getCandidat