码迷,mamicode.com
首页 > 编程语言 > 详细

Spring Boot Environment的初始化和预处理

时间:2018-04-08 22:25:20      阅读:851      评论:0      收藏:0      [点我收藏+]

标签:database   初始   list   nbsp   deb   config   alibaba   system   environ   

Spring Boot Environment的初始化和预处理实在启动时完成的, 即SpringApplication的run方法中。

ConfigurableEnvironment environment = prepareEnvironment(listeners,
                    applicationArguments);

Environment负责读取系统环境和参数信息, 包括但不限于以下几种属性源:

  1. 系统环境变量: System.getenv()
  2. JVM参数和Java命令行参数: System.getProperties()
  3. 程序参数, SpringApplication.run(Object source, String... args)
  4. WEB环境下, 还会读取context-parameter

这些信息保存在全局变量:(见AbstractEnvironment)

private final MutablePropertySources propertySources

在web环境中,加载的属性源列表: 

0 = {SimpleCommandLinePropertySource@1223} "SimpleCommandLinePropertySource {name=‘commandLineArgs‘}"    // SpringApplication.run(Object source, String... args)
1 = {PropertySource$StubPropertySource@1224} "StubPropertySource {name=‘servletConfigInitParams‘}"       // web环境特有
2 = {PropertySource$StubPropertySource@1225} "StubPropertySource {name=‘servletContextInitParams‘}"      // web环境特有
3 = {MapPropertySource@1226} "MapPropertySource {name=‘systemProperties‘}"                              // JVM参数和Java命令行参数: System.getProperties()
4 = {SystemEnvironmentPropertySource@1227} "SystemEnvironmentPropertySource {name=‘systemEnvironment‘}"  // 系统环境变量: System.getenv()

还有两个是通过

listeners.environmentPrepared(environment);

加载的:

5 = {RandomValuePropertySource@1693} "RandomValuePropertySource@735937428 {name=‘random‘, properties=java.util.Random@5f9edf14}"
6 = {ConfigFileApplicationListener$ConfigurationPropertySources@1694} "ConfigurationPropertySources@1752461090 {name=‘applicationConfigurationProperties‘, properties=[EnumerableCompositePropertySource@788625466 {name=‘applicationConfig: [profile=]‘, properties=[MapPropertySource@1753714541 {name=‘applicationConfig: [classpath:/application.yml]‘, properties={spring.application.name=example, spring.jackson.default-property-inclusion=non_null, spring.jpa.open-in-view=false, spring.jpa.hibernate.ddl-auto=none, spring.jpa.database=MYSQL, spring.jpa.show-sql=true, spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect, spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect, spring.aop.proxy-target-class=true, alibaba.druid.url=jdbc:mysql://localhost:3306/hotel?useUnicode=true&characterEncoding=utf-8, alibaba.druid.driver-class-name=com.mysql.jdbc.Driver, alibaba.druid.username=root, alibaba.druid.password=, logging.level.com.hotel=debug, logging.level.org.hibernate.SQL=debug, logging.level.org.springframework=debug, logging.file=hotel.log}}]}]}

 

Spring Boot Environment的初始化和预处理

标签:database   初始   list   nbsp   deb   config   alibaba   system   environ   

原文地址:https://www.cnblogs.com/javale/p/8747563.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!