springboot项目配置文件详解一

最近帮其他同事整理项目时,发现很多对springboot启动加载过程不是很了解,特地写一份文档说明,主要讲解boot项目启动过程

先看一个普通的springboot项目,配置如下

springboot项目配置文件详解一_第1张图片

这个可能还可以包含,sh文件,其他模板文件,证书文件等文件,都是基础文件,然后启动,日志如下:

第一部分

JDK参数+项目数据jar包+
2019-01-24 14:22:54.806 [main] INFO  org.springframework.context.annotation.AnnotationConfigApplicationContext [AbstractApplicationContext.java:590] - Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@10959ece: startup date [Thu Jan 24 14:22:54 CST 2019]; root of context hierarchy
2019-01-24 14:22:54.996 [main] INFO  com.ulisesbocchio.jasyptspringboot.configuration.EnableEncryptablePropertiesBeanFactoryPostProcessor [EnableEncryptablePropertiesBeanFactoryPostProcessor.java:50] - Post-processing PropertySource instances
2019-01-24 14:22:55.077 [main] INFO  com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceConverter [EncryptablePropertySourceConverter.java:38] - Converting PropertySource configurationProperties [org.springframework.boot.context.properties.source.ConfigurationPropertySourcesPropertySource] to AOP Proxy
2019-01-24 14:22:55.079 [main] INFO  com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceConverter [EncryptablePropertySourceConverter.java:38] - Converting PropertySource bootstrap [org.springframework.core.env.MapPropertySource] to EncryptableMapPropertySourceWrapper
2019-01-24 14:22:55.094 [main] INFO  org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor [AutowiredAnnotationBeanPostProcessor.java:153] - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2019-01-24 14:22:55.128 [main] INFO  org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker [PostProcessorRegistrationDelegate.java:326] - Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfigurationEnhancerBySpringCGLIBa6114ca0] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-01-24 14:22:55.153 [main] INFO  com.ulisesbocchio.jasyptspringboot.filter.DefaultLazyPropertyFilter [DefaultLazyPropertyFilter.java:31] - Property Filter custom Bean not found with name 'encryptablePropertyFilter'. Initializing Default Property Filter
2019-01-24 14:22:55.159 [main] INFO  com.ulisesbocchio.jasyptspringboot.resolver.DefaultLazyPropertyResolver [DefaultLazyPropertyResolver.java:31] - Property Resolver custom Bean not found with name 'encryptablePropertyResolver'. Initializing Default Property Resolver
2019-01-24 14:22:55.161 [main] INFO  com.ulisesbocchio.jasyptspringboot.detector.DefaultLazyPropertyDetector [DefaultLazyPropertyDetector.java:30] - Property Detector custom Bean not found with name 'encryptablePropertyDetector'. Initializing Default Property Detector

+启动图片
 :: Spring Boot ::        (v2.0.4.RELEASE)

此处为第一部分,主要是对jar包进行检查,额外添加了jasypt,此包主要是对数据库密码密文加密包,使数据库配置文件密文配置(加强防破解安全),实例如下图

springboot项目配置文件详解一_第2张图片

总之,再看到boot图像之前,都是对JAR的扫描过程

第二部分

2019-01-24 14:22:56.628 [main] INFO  org.springframework.cloud.config.client.ConfigServicePropertySourceLocator [ConfigServicePropertySourceLocator.java:205] - Fetching config from server at : http://localhost:7001/
2019-01-24 14:22:57.702 [main] INFO  org.springframework.cloud.config.client.ConfigServicePropertySourceLocator [ConfigServicePropertySourceLocator.java:227] - Connect Timeout Exception on Url - http://localhost:7001/. Will be trying the next url if available
2019-01-24 14:22:57.704 [main] WARN  org.springframework.cloud.config.client.ConfigServicePropertySourceLocator [ConfigServicePropertySourceLocator.java:140] - Could not locate PropertySource: I/O error on GET request for "http://localhost:7001/app-service/dev/master": Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect
2019-01-24 14:22:57.707 [main] INFO  com.ulisesbocchio.jasyptspringboot.configuration.EnableEncryptablePropertiesConfiguration [EnableEncryptablePropertiesConfiguration.java:69] - Bootstraping jasypt-string-boot auto configuration in context: oauth-server-1
2019-01-24 14:22:57.708 [main] INFO  com.wjx.authorization.AuthorizationApplication [SpringApplication.java:666] - The following profiles are active: test1

讲这部分之前还是给小白讲讲,一般默认的boot文件的加载顺序(很重要!):

   bootstrap   >   yml    > properties

说明一下,优先加载不一定生效,一般如果不同文件存在相同配置,则后加载会覆盖优先级高的,具体可看源码

所以我们可以看到,第一个加载的是bootstrap关于git的自动化配置,如下图

springboot项目配置文件详解一_第3张图片

项目会先找7001端口的配置中心服务(此springcloudConfig服务服务暂未开启,所以超时Connect Timeout Exception on Url),一般如果配置中心正确,就会优先读取配置中心配置信息,配置中心如下

springboot项目配置文件详解一_第4张图片

只需添加ouath-server.properties文件,就可以将配置权限都交给config中心处理

当然今天主要不是讲这个,继续看日志发现,找不到7001服务后,继续读取application.yml(默认读取文件),文件如下

spring.profiles代表spring加载参数,active代表那个文件生效。test1是指文件名,流程很清晰,文章太长了,后面二接着讲

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(cloud)