首页
统计
关于
Search
1
Sealos3.0离线部署K8s集群
1,073 阅读
2
类的加载
737 阅读
3
Spring Cloud OAuth2.0
725 阅读
4
SpringBoot自动装配原理
689 阅读
5
集合不安全问题
582 阅读
笔记
Java
多线程
注解和反射
JVM
JUC
设计模式
Mybatis
Spring
SpringMVC
SpringBoot
MyBatis-Plus
Elastic Search
微服务
Dubbo
Zookeeper
SpringCloud
Nacos
Sentinel
数据库
MySQL
Oracle
PostgreSQL
Redis
MongoDB
工作流
Activiti7
Camunda
消息队列
RabbitMQ
前端
HTML5
CSS
CSS3
JavaScript
jQuery
Vue2
Vue3
Linux
容器
Docker
Kubernetes
Python
登录
Search
标签搜索
Java
CSS
mysql
RabbitMQ
JavaScript
Redis
JVM
Mybatis-Plus
Camunda
多线程
CSS3
Python
Spring Cloud
注解和反射
Activiti
工作流
SpringBoot
Mybatis
Spring
html5
蘇阿細
累计撰写
388
篇文章
累计收到
4
条评论
首页
栏目
笔记
Java
多线程
注解和反射
JVM
JUC
设计模式
Mybatis
Spring
SpringMVC
SpringBoot
MyBatis-Plus
Elastic Search
微服务
Dubbo
Zookeeper
SpringCloud
Nacos
Sentinel
数据库
MySQL
Oracle
PostgreSQL
Redis
MongoDB
工作流
Activiti7
Camunda
消息队列
RabbitMQ
前端
HTML5
CSS
CSS3
JavaScript
jQuery
Vue2
Vue3
Linux
容器
Docker
Kubernetes
Python
页面
统计
关于
搜索到
7
篇与
的结果
2021-01-01
Spring Cloud Config分布式配置中心
Spring Cloud ConfigSpring Cloud Config为微服务架构中的微服务提供集中化的外部配置支持,配置服务器为各个不同微服务应用的所有环节提供了一个中心化的外部配置。Spring Cloud Config分为客户端和服务端:服务端:分布式配置中心,它是一个独立的微服务应用,用来连接配置服务器,并为客户端提供获取配置信息,加密,解密信息等访问接口客户端:通过指定的配置中心来管理应用资源,以及与业务相关的配置内容,并在启动的时候从配置中心获取和加载配置信息。配置服务器默认采用git来存储配置信息,这样有助于对环境配置进行版本管理。作用:集中管理配置文件不同环境,不同配置,动态化的配置更新,分环境部署,如:开发、测试、生产等环境运行期间可以动态调整配置,不再需要在每个服务部署的机器上编写配置文件,服务会向配置中心统一拉取配置自己的信息当配置发生变动时,服务节点不需要重启,动态应用新的配置配置信息以REST接口的形式暴露图片来源:狂神说Java具体实例1、服务端pom依赖:<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> <version>2.1.1.RELEASE</version> </dependency> <!--actuator监控信息--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> </dependencies>application.yml配置:server: port: 3344 spring: application: name: springcloud-config-server #连接远程仓库 cloud: config: server: git: uri: https://github.com/suaxi/SpringCloud-config.gitSpringBoot启动类开启ConfigServer注解:package com.sw.springcloud; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.config.server.EnableConfigServer; /** * @Author suaxi * @Date 2020/12/30 14:49 */ @SpringBootApplication @EnableConfigServer public class Config_Server_3344 { public static void main(String[] args) { SpringApplication.run(Config_Server_3344.class,args); } } 2、客户端pom依赖:<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> <version>2.1.1.RELEASE</version> </dependency> <!--actuator监控信息--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> </dependencies>bootstrap.yml配置:#系统级别的配置 spring: cloud: config: name: config-client #需要从远程仓库读取的资源名称 profile: dev #版本 label: master #分支 uri: http://localhost:3344 #获取配置信息的地址(Config配置服务端)application.yml配置:#用户级别的配置 spring: application: name: springcloud-config-client-3355Controller(配置REST接口)package com.sw.springcloud.controller; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * @Author suaxi * @Date 2020/12/30 15:29 */ @RestController public class ConfigClientController { @Value("${spring.application.name}") private String applicationName; @Value("${eureka.client.service-url.defaultZone}") private String eurekaServer; @Value("${server.port}") private String port; @RequestMapping("/config") public String getConfig(){ return "applicationName:"+applicationName+ "eurekaServer:"+eurekaServer+ "port:"+port; } } 3、Eureka服务注册中心pom依赖:<dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> <version>1.4.7.RELEASE</version> </dependency> <!--config--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> <version>2.1.1.RELEASE</version> </dependency> </dependencies>bootstrap.yml配置:与config配置中心的客户端一致,都是从Config服务端获取配置信息spring: cloud: config: name: config-eureka label: master profile: dev uri: http://localhost:3344application.yml配置:spring: application: name: springcloud-config-eureka-7001SpringBoot启动类:package com.sw.springcloud; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; /** * @Author suaxi * @Date 2020/12/29 11:02 */ @SpringBootApplication @EnableEurekaServer //服务端 public class EurekaConfigServer_7001 { public static void main(String[] args) { SpringApplication.run(EurekaConfigServer_7001.class,args); } } 4、Eureka服务提供者pom依赖:<dependencies> <!--需要拿到实体类,配置api module--> <dependency> <groupId>com.sw</groupId> <artifactId>springcloud-api</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-core</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jetty</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> <version>1.4.7.RELEASE</version> </dependency> <!--actuator监控信息--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix</artifactId> <version>1.4.7.RELEASE</version> </dependency> <!--config--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> <version>2.1.1.RELEASE</version> </dependency> </dependencies>bootstrap.yml配置:与以上两个的配置一致,都是从Config服务端获取配置信息spring: cloud: config: name: config-dept label: master profile: dev uri: http://localhost:3344application.yml配置:spring: application: name: springcloud-config-dept-8088服务提供者对比之前的配置(application.yml):通过Config分布式配置中心,将配置文件放到git统一管理,现只需从Config-server获取即可server: port: 8088 #mybatis配置 mybatis: type-aliases-package: com.sw.springcloud.pojo config-location: classpath:mybatis/mybatis-config.xml mapper-locations: classpath:mybatis/mapper/*.xml #Spring配置 spring: application: name: springcloud-provider-dept datasource: type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/db01?useUnicode=true&character=UFT-8 username: root password: 123456 #配置Eureka,配置服务注册到哪里 eureka: client: service-url: defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/ instance: instance-id: springcloud-provider_dept8088 #修改Eureka默认描述信息 prefer-ip-address: true #显示服务的真实ip地址,替换原先的localhost #info配置 info: app.name: springcloud-demo company.name: suaxi 配置文件交由git统一管理
2021年01月01日
80 阅读
0 评论
0 点赞
2020-12-26
定时任务
定时任务1、SpringBoot启动类开启定时任务注解package com.sw; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; @EnableScheduling //开启定时任务 @SpringBootApplication public class Springboot09AsynctaskApplication { public static void main(String[] args) { SpringApplication.run(Springboot09AsynctaskApplication.class, args); } } 2、测试package com.sw.service; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; /** * @Author suaxi * @Date 2020/12/26 17:35 * 定时任务 */ @Service public class ScheduledService { /* cron:秒 分 时 日 月 周几 0/3 * * * * 0-7 周一到周日每三秒执行一次 0 0 21 26 12 ? 12月26日21时执行 */ @Scheduled(cron = "0/3 * * * * 0-7") public void hello(){ System.out.println("抽象!"); } } 注:定时任务需使用cron表达式来源:cron百度百科 0 0 2 1 * ? * 表示在每月的1日的凌晨2点调度任务 0 15 10 ? * MON-FRI 表示周一到周五每天上午10:15执行作业 0 15 10 ? * 6L 2002-2006 表示2002-2006年的每个月的最后一个星期五上午10:15执行作 0 0 10,14,16 * * ? 每天上午10点,下午2点,4点 0 0/30 9-17 * * ? 朝九晚五工作时间内每半小时 0 0 12 ? * WED 表示每个星期三中午12点 "0 0 12 * * ?" 每天中午12点触发 "0 15 10 ? * *" 每天上午10:15触发 "0 15 10 * * ?" 每天上午10:15触发 "0 15 10 * * ? *" 每天上午10:15触发 "0 15 10 * * ? 2005" 2005年的每天上午10:15触发 "0 * 14 * * ?" 在每天下午2点到下午2:59期间的每1分钟触发 "0 0/5 14 * * ?" 在每天下午2点到下午2:55期间的每5分钟触发 "0 0/5 14,18 * * ?" 在每天下午2点到2:55期间和下午6点到6:55期间的每5分钟触发 "0 0-5 14 * * ?" 在每天下午2点到下午2:05期间的每1分钟触发 "0 10,44 14 ? 3 WED" 每年三月的星期三的下午2:10和2:44触发 "0 15 10 ? * MON-FRI" 周一至周五的上午10:15触发 "0 15 10 15 * ?" 每月15日上午10:15触发 "0 15 10 L * ?" 每月最后一日的上午10:15触发 "0 15 10 ? * 6L" 每月的最后一个星期五上午10:15触发 "0 15 10 ? * 6L 2002-2005" 2002年至2005年的每月的最后一个星期五上午10:15触发 "0 15 10 ? * 6#3" 每月的第三个星期五上午10:15触发
2020年12月26日
117 阅读
0 评论
0 点赞
2020-12-26
异步任务
异步任务1、Servicepackage com.sw.service; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; /** * @Author suaxi * @Date 2020/12/26 15:57 */ @Service public class AsyncService { //告诉Spring这是一个异步任务 @Async public void hello(){ try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("数据正在加载..."); } } 2、Controllerpackage com.sw.controller; import com.sw.service.AsyncService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * @Author suaxi * @Date 2020/12/26 15:58 */ @RestController public class AsyncController { @Autowired private AsyncService asyncService; @RequestMapping("/test") public String hello(){ asyncService.hello(); return "Ok"; } } 3、SpringBoot启动类开启异步任务的注解package com.sw; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; @EnableAsync //开启异步任务注解 @SpringBootApplication public class Springboot09AsynctaskApplication { public static void main(String[] args) { SpringApplication.run(Springboot09AsynctaskApplication.class, args); } } 当用户执行/test请求时,前端页面及时返回结果,同时异步任务延迟三秒在控制台打印输出结果
2020年12月26日
196 阅读
0 评论
0 点赞
2020-12-26
Swagger
SwaggerSwagger 是一个规范和完整的框架,用于生成、描述、调用和可视化 RESTful 风格的 Web 服务。1、导入依赖<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.9.2</version> </dependency>2、SwaggerConfig配置package com.sw.swagger.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; import org.springframework.core.env.Profiles; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.ApiInfo; import springfox.documentation.service.Contact; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; import java.util.ArrayList; /** * @Author suaxi * @Date 2020/12/26 11:03 */ @Configuration @EnableSwagger2 public class SwaggerConfig { //配置Swagger的Docket @Bean public Docket docket(Environment environment) { //配置哪种环境下需要启用Swagger Profiles profiles = Profiles.of("dev", "test"); //监听配置文件 boolean flag = environment.acceptsProfiles(profiles); //链式编程 return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .enable(flag) //配置是否启动Swagger,默认为true,如需关闭须手动设置为false .select() //RequestHandlerSelectors 配置扫描接口的方式 //basePackage() 指定要扫描的包 //any() 扫描全部 //none() 不扫描 //withClassAnnotation(Controller.class) 扫描类注解(参数是一个注解的反射对象) //withMethodAnnotation(RequestMapping.class) 扫描方法上的注解 .apis(RequestHandlerSelectors.basePackage("com.sw.swagger.controller")) //paths() 过滤的路径 .paths(PathSelectors.ant("/**")) .build(); } //配置Swagger apiInfo private ApiInfo apiInfo(){ //作者信息 Contact contact = new Contact("suaix","http://wangchouchou.com","281463547@qq.com"); return new ApiInfo( "Swagger StudyDemo", "SwaggerStudy", "1.0", "http://wangchouchou.com", contact, "Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0", new ArrayList()); } } Docket配置//配置Swagger的Docket @Bean public Docket docket(Environment environment) { //配置哪种环境下需要启用Swagger Profiles profiles = Profiles.of("dev", "test"); //监听配置文件 boolean flag = environment.acceptsProfiles(profiles); //链式编程 return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .enable(flag) //配置是否启动Swagger,默认为true,如需关闭须手动设置为false .select() //RequestHandlerSelectors 配置扫描接口的方式 //basePackage() 指定要扫描的包 //any() 扫描全部 //none() 不扫描 //withClassAnnotation(Controller.class) 扫描类注解(参数是一个注解的反射对象) //withMethodAnnotation(RequestMapping.class) 扫描方法上的注解 .apis(RequestHandlerSelectors.basePackage("com.sw.swagger.controller")) //paths() 过滤的路径 .paths(PathSelectors.ant("/**")) .build(); }配置什么环境下需要使用Swagger通过监听配置文件实现//配置那种环境下需要启用Swagger Profiles profiles = Profiles.of("dev", "test"); //监听配置文件 boolean flag = environment.acceptsProfiles(profiles); 3、配置文档分组.groupName("Demo")如何配置实现多个分组?配置多个Docket实例即可4、实体类package com.sw.swagger.pojo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; /** * @Author suaxi * @Date 2020/12/26 14:39 */ //@Api("用户实体类") @ApiModel("用户实体类") public class User { @ApiModelProperty("用户名") public String username; @ApiModelProperty("密码") public String password; } 5、Controllerpackage com.sw.swagger.controller; import com.sw.swagger.pojo.User; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RestController; /** * @Author suaxi * @Date 2020/12/26 10:59 */ @RestController public class HelloController { @ApiOperation("POST测试") @PostMapping("/hello") public String helloTest(@ApiParam("用户名") String username){ return "swagger-springboot"; } @ApiOperation("返回User对象") @PostMapping("/u") public User user(){ return new User(); } @ApiOperation("Hello控制类") @GetMapping("/h") public String hello(){ return "swagger-springboot"; } } 小结:1、通过Swagger可以给一些难以理解的属性或接口添加注释信息2、接口文档实时更新3、在线测试
2020年12月26日
297 阅读
1 评论
0 点赞
2020-12-26
SpringSecurity
SpringSecurity1、导入依赖<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency>2、Config配置package com.sw.config; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; /** * @Author suaxi * @Date 2020/12/24 14:45 */ @EnableWebSecurity public class SercurityConfig extends WebSecurityConfigurerAdapter { //授权 @Override protected void configure(HttpSecurity http) throws Exception { //首页所有人可以访问,功能页需要权限才能访问 //请求授权规则 http.authorizeRequests() .antMatchers("/").permitAll() .antMatchers("/level1/*").hasRole("vip1") .antMatchers("/level2/*").hasRole("vip2") .antMatchers("/level3/*").hasRole("vip3"); //没有权限,默认跳转到登录页 //自定义登录页 http.formLogin().loginPage("/toLogin").loginProcessingUrl("/login"); http.csrf().disable(); //注销 http.logout().logoutSuccessUrl("/"); //开启记住我 //自定义rememberMe http.rememberMe().rememberMeParameter("remember"); } //认证 @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { //在内存中虚拟用户 auth.inMemoryAuthentication().passwordEncoder(new BCryptPasswordEncoder()) .withUser("1").password(new BCryptPasswordEncoder().encode("1")).roles("vip1") .and() .withUser("2").password(new BCryptPasswordEncoder().encode("1")).roles("vip2") .and() .withUser("3").password(new BCryptPasswordEncoder().encode("1")).roles("vip3") .and() .withUser("root").password(new BCryptPasswordEncoder().encode("1")).roles("vip1","vip2","vip3"); } }
2020年12月26日
309 阅读
0 评论
0 点赞
2020-12-22
yaml配置
yaml配置文件application.properties语法结构:key=valueapplication.yaml语法结构:key:空格 valueyamlYAML是"YAML Ain't a Markup Language"(YAML不是一种标记语言)的递归缩写。基本语法:# k=v name: test #对象 student: name: test age: 3 #行内写法 student1: {name: test,age: 3} #数组 students: -test1 -test2 -test3 students1: [test1,test2,test3]注入配置文件1、导入配置文件的依赖<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency>2、yaml配置文件person: name: test age: 3 happy: false birth: 2020/12/22 map: {k: v,k1: v1} list: -code -girl dog: name: test age: 33、实体类package com.sw.pojo; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; import java.util.Date; import java.util.List; import java.util.Map; /** * @Author suaxi * @Date 2020/12/22 10:38 */ @Data @AllArgsConstructor @NoArgsConstructor @Component //注册Bean @ConfigurationProperties(prefix = "person") public class Person { private String name; private int age; private Boolean happy; private Date birth; private Map<String,Object> map; private List<Object> list; private Dog dog; } @ConfigurationProperties的作用:将配置文件中配置的每一个属性的值,映射到这个组件中,参数prefix = "person",将配置文件中person下的所有属性一一对应补充:通过properties注入属性@PropertySource(value = "classpath:application.properties")properties与yaml对比 @ConfigurationProperties@value功能批量注入配置文件中的属性需单个一一指定松散绑定是否SPEL表达式否是JSR303校验是否复杂类型封装是否松散绑定:yaml中写的是last-name,实体类中写的是lastName,值依然能注入,yaml中 - 后面的第一个字母默认大写JSR303校验:JSR是Java Specification Requests的缩写,意思是Java 规范提案。使用时须在实体类前加上注解 @Validated //JSR303校验
2020年12月22日
94 阅读
0 评论
0 点赞
2020-12-22
SpringBoot自动装配原理
SpringBoot自动装配原理pom.xmlSpring-boot-dependencies:核心依赖在父工程中导入依赖时不用指定版本,因为有版本仓库启动器:SpringBoot的启动场景例:spring-boot-starter-web,会自动导入web环境所有的依赖SpringBoot会将所有的功能场景,都变成一个个的启动器主程序:package com.sw.helloworld; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication //标注这是一个SpringBoot应用 public class HelloworldApplication { public static void main(String[] args) { //启动SpringBoot SpringApplication.run(HelloworldApplication.class, args); } } 1、SpringBoot在启动的时候从类路径下的META-INF/spring.factories中获取AutoConfiguration指定的值2、将这些值作为自动配置类导入容器,自动配置类生效3、J2EE的整体解决方案和自动配置都在SpringBoot-autoConfig的jar包中4、它会将需要的组件以全类名的方式返回,这些组件就会被添加到容器中5、他会给容器中导入非常多的配置类,也就是导入并配置这个场景所需要的组件@SpringApplication(启动类注解) ---> @EnableAutoConfiguration(自动配置注解) ---> @Import(AutoConfigurationSelector.class)(自动导入配置文件的选择器) ---> getCandidateConfigurations()(获取所有候选配置) ---> 通过spring.factories获取配置类的位置 ---> @ConditionOnClass判断 ---> 条件成立(不加载该配置类) ---> 条件不成立(获取配置类,在上层方法中循环封装为properties来使用)xxxAutoConfiguration:自动配置类(给容器中添加组件)xxxProperties:封装配置文件中的相关属性(application.yaml)SpringApplication:1、推断应用的类型是普通项目还是web项目2、查找并加载所有可用初始化器,设置到initializers属性中3、找出所有的应用程序监听器,设置到listeners属性中4、推断并设置main方法的定义类,找到运行的主类
2020年12月22日
689 阅读
0 评论
0 点赞