properties全部配置二,SpringBoot入门教程

前方的篇章已经介绍了CentOS布置SpringBoot项目从0到1的详实进度,富含Linux安装ftp、汤姆cat以及Java
jdk的满贯历程。那篇小说主要介绍有关springboot怎么样通过八个properties实现数据库意况布署时自动切换配置的二种艺术,铺排时切换方式和包裹时Maven调整措施。

至于springboot基础矿建搭建有疑点的。能够看自身在此以前的一篇文章。详解intellij
idea搭建SpringBoot


SOLR (SolrProperties)

spring.data.solr.host=http://127.0.0.1:8983/solr
# Solr host. Ignored if “zk-host” is set.
spring.data.solr.repositories.enabled=true # Enable Solr
repositories.
spring.data.solr.zk-host= # ZooKeeper host address in the form
HOST:PORT.

ca88亚洲城网站 1

v意况介绍

健康来说,四个软件的支出上线的流水生产线半数以上都以分为三个景况,依次是支付、测验、上线。

支付遭逢:

付出情状是指的是大家本地跑的条件。

测量检验景况:

平日是仿制一份生产条件的布局,qa即test。

生育条件

行业内部提供对外地劳工务的,正是真实遇到。

关于多少个碰到的切换已然标准化了,这里只是单笔带过一下,因为下文中的配置文件会跟两个情况有提到。相信全部人都不会对那多个条件目生的。

后天首要讲讲关于springboot怎样通过四个properties达成数据库意况布置时自动切换配置的三种艺术,安插时切换方式和打包时Maven调控方法。首先介绍陈设时切换的不二法门。

========================================

DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)

spring.datasource.continue-on-error=false # Do not stop if an error
occurs while initializing the database.
spring.datasource.data= # Data (DML) script resource reference.
spring.datasource.driver-class-name= # Fully qualified name of the JDBC
driver. Auto-detected based on the URL by default.
spring.datasource.initialize=true # Populate the database using
‘data.sql’.
spring.datasource.jmx-enabled=false # Enable JMX support (if provided
by the underlying pool).
spring.datasource.jndi-name= # JNDI location of the datasource. Class,
url, username & password are ignored when set.
spring.datasource.max-active= # For instance 100
spring.datasource.max-idle= # For instance 8
spring.datasource.max-wait=
spring.datasource.min-evictable-idle-time-millis=
spring.datasource.min-idle=8
spring.datasource.name=testdb # Name of the datasource.
spring.datasource.password= # Login password of the database.
spring.datasource.platform=all # Platform to use in the schema resource
(schema-${platform}.sql).
spring.datasource.schema= # Schema (DDL) script resource reference.
spring.datasource.separator=; # Statement separator in SQL
initialization scripts.
spring.datasource.sql-script-encoding= # SQL scripts encoding.
spring.datasource.test-on-borrow= # For instance false
spring.datasource.test-on-return= # For instance false
spring.datasource.test-while-idle= #
spring.datasource.time-between-eviction-runs-millis= 1
spring.datasource.type= # Fully qualified name of the connection pool
implementation to use. By default, it is auto-detected from the
classpath.
spring.datasource.url= # JDBC url of the database.
spring.datasource.username=
spring.datasource.validation-query=

←←←←←←←←←←←← 快!点关注

v布置时切换

1.1 配置dev和qa境遇数据,以备测量试验。

ca88亚洲城网站 2

1.2 新增properties文件

ca88亚洲城网站 3

如上图:在application.properties文件的同级目录依次创设application-dev.properties,application-qa.properties,application-pro.properties那多少个布局文件,dev、qa和prod分别对应上文”情形介绍”中的四个条件。

1.3 配置各样properties文件

在application.properties中增加配置切换选项,比如切换成dev境况的配置为:spring.profiles.active=dev

梯次在application-dev.properties,application-qa.properties,application-pro.properties配置相关datasource连接消息。

例如application-dev.properties配置:

spring.datasource.url=jdbc:mysql://127.0.0.1:3306/mytestspring.datasource.username=rootspring.datasource.password=***********spring.datasource.driver-class-name=com.mysql.jdbc.Driver

ca88亚洲城网站 4

1.4 本地境况

当设置application.properties中spring.profiles.active=dev时,则此时运营连接的是dev情状。

ca88亚洲城网站 5

如上图,此时运作获得的结果与计划文件一律,是dev情形的数目。

1.5 陈设测量检验碰着

布局测量检验碰着,关于安排有不打听的能够看看《CentOS铺排SpringBoot项目从0到1》,安插时切换成qa蒙受。

java -jar zuche-0.0.1-SNAPSHOT.jar --spring.profiles.active=qa --server.port=2008

ca88亚洲城网站 6

可以看来日志中显得的剧情与预期一致,spring.profiles.active设置为qa,
端口设置为二零零六。

运作效果如下图,铺排以往连接的qa景况。

ca88亚洲城网站 7

CORE PROPERTIES


========================================

H2 Web Console (H2ConsoleProperties)

spring.h2.console.enabled=false # Enable the console.
spring.h2.console.path=/h2-console # Path at which the console will be
available.

信赖接触过 SpringBoot 的对象都知道 SpringBoot 有种种 starter
依赖,想要什么直接勾选加进去就可以了。想要自定义的时候就径直在布局文件写本人的布署就好。但你们有未有困惑,为啥SpringBoot 如此智能,到底配置文件之中能写什么吧?

vMaven调整打包时切换

2.1 设置项目对象模型pom.xml

2.1.1 增多profiles到pom.xml中,profiles节点是和build同级的。

    <profiles>        <profile>            <id>dev</id>            <properties>                <env>dev</env>            </properties>            <activation>                <activeByDefault>true</activeByDefault>            </activation>        </profile>        <profile>            <id>qa</id>            <properties>                <env>qa</env>            </properties>        </profile>        <profile>            <id>prod</id>            <properties>                <env>prod</env>            </properties>        </profile>    </profiles>

activation代表的是能够用这么的授命来触发profile,true代表dev是暗中认可的profile,
那样地方一贯ide运营项目标时候正是连接的dev情形。

2.1.2 添加filters节点。

        <filters>            <filter>src/main/resources/application-${env}.properties</filter>        </filters>

ca88亚洲城网站 8

2.2 更新application.properties。

spring.profiles.active=@env@

在乎@env@中的env能够精晓为三个变量,要求与2.1.第22中学装置的${env}对应上。

2.3 增多Maven打包命令

clean package -P qa -D maven.test.skip=true

ca88亚洲城网站 9

-D maven.test.skip=trueca88亚洲城网站,不执行测量试验用例,也不编写翻译测量检验用例类。

2.4 执行Maven命令

ca88亚洲城网站 10

查阅jar包的application.properties文件的spring.profiles.active,看Maven命令是还是不是见效。

ca88亚洲城网站 11

如上图,spring.profiles.active=qa

2.5 部署Tomcat

java -jar zuche-0.0.1-SNAPSHOT.jar --server.port=2008

ca88亚洲城网站 12

Maven打包时已经安装了qa情况,安顿命令中无需再指明qa情形。

BANNER

banner.charset=UTF-8 # Banner file encoding.
banner.location=classpath:banner.txt # Banner file location.

JOOQ (JooqAutoConfiguration)

spring.jooq.sql-dialect= # SQLDialect JOOQ used when communicating with
the configured datasource. For instance POSTGRES

带着那么些疑问,笔者翻了下 SpringBoot 官方网址见到这么一些布局样例:

v博客总计

本文通篇讲的基本点是围绕springboot安插jar包的二种格局,至于war包,现在一时间再说说。

LOGGING

logging.config= # Location of the logging configuration file. For
instance classpath:logback.xml for Logback
logging.exception-conversion-word=%wEx # Conversion word used when
logging exceptions.
logging.file= # Log file name. For instance myapp.log
logging.level.*= # Log levels severity mapping. For instance
logging.level.org.springframework=DEBUG
logging.path= # Location of the log file. For instance /var/log
logging.pattern.console= # Appender pattern for output to the console.
Only supported with the default logback setup.
logging.pattern.file= # Appender pattern for output to the file. Only
supported with the default logback setup.
logging.pattern.level= # Appender pattern for log level (default %5p).
Only supported with the default logback setup.
logging.register-shutdown-hook=false #properties全部配置二,SpringBoot入门教程。 Register a shutdown hook for the
logging system when it is initialized.

JPA (JpaBaseConfiguration, HibernateJpaAutoConfiguration)

spring.data.jpa.repositories.enabled=true # Enable JPA repositories.
spring.jpa.database= # Target database to operate on, auto-detected by
default. Can be alternatively set using the “databasePlatform”
property.
spring.jpa.database-platform= # Name of the target database to operate
on, auto-detected by default. Can be alternatively set using the
“Database” enum.
spring.jpa.generate-ddl=false # Initialize the schema on startup.
spring.jpa.hibernate.ddl-auto= # DDL mode. This is actually a shortcut
for the “hibernate.hbm2ddl.auto” property. Default to “create-drop” when
using an embedded database, “none” otherwise.
spring.jpa.hibernate.naming-strategy= # Naming strategy fully qualified
name.
spring.jpa.open-in-view=true # Register
OpenEntityManagerInViewInterceptor. Binds a JPA EntityManager to the
thread for the entire processing of the request.
spring.jpa.properties.*= # Additional native properties to set on the
JPA provider.
spring.jpa.show-sql=false # Enable logging of SQL statements.

ca88亚洲城网站 13SpringBoot
配置样例

v源码地址

作  者:请叫我头头哥
出  处:
有关作者:潜心于基础平台的类别支出。如至极或提出,请多多赐教!
版权评释:本文版权归作者和新浪共有,应接转发,但未经小编同意必得保留此段注明,且在篇章页面明显地点给出原作链接。
特此评释:全部评价和私信都会在第不经常间回复。也招待园子的大大们指正错误,共同进步。可能直接私信小编
扶持博主:假诺您以为小说对你有支持,能够点击文章右下角**立刻。您的砥砺是小编坚定不移原创和相连写作的最大引力!

AOP

spring.aop.auto=true # Add @EnableAspectJAutoProxy.
spring.aop.proxy-target-class=false # Whether subclass-based (CGLIB)
proxies are to be created (true) as opposed to standard Java
interface-based proxies (false).

JTA (JtaAutoConfiguration)

spring.jta.*= # technology specific configuration
spring.jta.log-dir= # Transaction logs directory.

发掘 SpringBoot
可配备的事物比较多,上海体育地方只是节选。有意思味的查看这么些网站:

IDENTITY (ContextIdApplicationContextInitializer)

spring.application.index= # Application index.
spring.application.name= # Application name.

ATOMIKOS

spring.jta.atomikos.connectionfactory.borrow-connection-timeout=30 #
Timeout, in seconds, for borrowing connections from the pool.
spring.jta.atomikos.connectionfactory.ignore-session-transacted-flag=true
# Whether or not to ignore the transacted flag when creating session.
spring.jta.atomikos.connectionfactory.local-transaction-mode=false #
Whether or not local transactions are desired.
spring.jta.atomikos.connectionfactory.maintenance-interval=60 # The
time, in seconds, between runs of the pool’s maintenance thread.
spring.jta.atomikos.connectionfactory.max-idle-time=60 # The time, in
seconds, after which connections are cleaned up from the pool.
spring.jta.atomikos.connectionfactory.max-lifetime=0 # The time, in
seconds, that a connection can be pooled for before being destroyed. 0
denotes no limit.
spring.jta.atomikos.connectionfactory.max-pool-size=1 # The maximum
size of the pool.
spring.jta.atomikos.connectionfactory.min-pool-size=1 # The minimum
size of the pool.
spring.jta.atomikos.connectionfactory.reap-timeout=0 # The reap
timeout, in seconds, for borrowed connections. 0 denotes no limit.
spring.jta.atomikos.connectionfactory.unique-resource-name=jmsConnectionFactory
# The unique name used to identify the resource during recovery.
spring.jta.atomikos.datasource.borrow-connection-timeout=30 # Timeout,
in seconds, for borrowing connections from the pool.
spring.jta.atomikos.datasource.default-isolation-level= # Default
isolation level of connections provided by the pool.
spring.jta.atomikos.datasource.login-timeout= # Timeout, in seconds,
for establishing a database connection.
spring.jta.atomikos.datasource.maintenance-interval=60 # The time, in
seconds, between runs of the pool’s maintenance thread.
spring.jta.atomikos.datasource.max-idle-time=60 # The time, in seconds,
after which connections are cleaned up from the pool.
spring.jta.atomikos.datasource.max-lifetime=0 # The time, in seconds,
that a connection can be pooled for before being destroyed. 0 denotes no
limit.
spring.jta.atomikos.datasource.max-pool-size=1 # The maximum size of
the pool.
spring.jta.atomikos.datasource.min-pool-size=1 # The minimum size of
the pool.
spring.jta.atomikos.datasource.reap-timeout=0 # The reap timeout, in
seconds, for borrowed connections. 0 denotes no limit.
spring.jta.atomikos.datasource.test-query= # SQL query or statement
used to validate a connection before returning it.
spring.jta.atomikos.datasource.unique-resource-name=dataSource # The
unique name used to identify the resource during recovery.

此间作者拿以前创设过的 SpringBoot 来比喻解说 SpringBoot
的活动配置原理,首先看这么一段代码:

ADMIN (SpringApplicationAdminJmxAutoConfiguration)

spring.application.admin.enabled=false # Enable admin features for the
application.
spring.application.admin.jmx-name=org.springframework.boot:type=Admin,name=SpringApplication
# JMX name of the application admin MBean.

BITRONIX

spring.jta.bitronix.connectionfactory.acquire-increment=1 # Number of
connections to create when growing the pool.
spring.jta.bitronix.connectionfactory.acquisition-interval=1 # Time, in
seconds, to wait before trying to acquire a connection again after an
invalid connection was acquired.
spring.jta.bitronix.connectionfactory.acquisition-timeout=30 # Timeout,
in seconds, for acquiring connections from the pool.
spring.jta.bitronix.connectionfactory.allow-local-transactions=true #
Whether or not the transaction manager should allow mixing XA and non-XA
transactions.
spring.jta.bitronix.connectionfactory.apply-transaction-timeout=false #
Whether or not the transaction timeout should be set on the XAResource
when it is enlisted.
spring.jta.bitronix.connectionfactory.automatic-enlisting-enabled=true
# Whether or not resources should be enlisted and delisted
automatically.
spring.jta.bitronix.connectionfactory.cache-producers-consumers=true #
Whether or not produces and consumers should be cached.
spring.jta.bitronix.connectionfactory.defer-connection-release=true #
Whether or not the provider can run many transactions on the same
connection and supports transaction interleaving.
spring.jta.bitronix.connectionfactory.ignore-recovery-failures=false #
Whether or not recovery failures should be ignored.
spring.jta.bitronix.connectionfactory.max-idle-time=60 # The time, in
seconds, after which connections are cleaned up from the pool.
spring.jta.bitronix.connectionfactory.max-pool-size=10 # The maximum
size of the pool. 0 denotes no limit.
spring.jta.bitronix.connectionfactory.min-pool-size=0 # The minimum
size of the pool.
spring.jta.bitronix.connectionfactory.password= # The password to use
to connect to the JMS provider.
spring.jta.bitronix.connectionfactory.share-transaction-connections=false
# Whether or not connections in the ACCESSIBLE state can be shared
within the context of a transaction.
spring.jta.bitronix.connectionfactory.test-connections=true # Whether
or not connections should be tested when acquired from the pool.
spring.jta.bitronix.connectionfactory.two-pc-ordering-position=1 # The
position that this resource should take during two-phase commit (always
first is Integer.MIN_VALUE, always last is Integer.MAX_VALUE).
spring.jta.bitronix.connectionfactory.unique-name=jmsConnectionFactory
# The unique name used to identify the resource during recovery.
spring.jta.bitronix.connectionfactory.use-tm-join=true Whether or not
TMJOIN should be used when starting XAResources.
spring.jta.bitronix.connectionfactory.user= # The user to use to
connect to the JMS provider.
spring.jta.bitronix.datasource.acquire-increment=1 # Number of
connections to create when growing the pool.
spring.jta.bitronix.datasource.acquisition-interval=1 # Time, in
seconds, to wait before trying to acquire a connection again after an
invalid connection was acquired.
spring.jta.bitronix.datasource.acquisition-timeout=30 # Timeout, in
seconds, for acquiring connections from the pool.
spring.jta.bitronix.datasource.allow-local-transactions=true # Whether
or not the transaction manager should allow mixing XA and non-XA
transactions.
spring.jta.bitronix.datasource.apply-transaction-timeout=false #
Whether or not the transaction timeout should be set on the XAResource
when it is enlisted.
spring.jta.bitronix.datasource.automatic-enlisting-enabled=true #
Whether or not resources should be enlisted and delisted
automatically.
spring.jta.bitronix.datasource.cursor-holdability= # The default cursor
holdability for connections.
spring.jta.bitronix.datasource.defer-connection-release=true # Whether
or not the database can run many transactions on the same connection and
supports transaction interleaving.
spring.jta.bitronix.datasource.enable-jdbc4-connection-test= # Whether
or not Connection.isValid() is called when acquiring a connection from
the pool.
spring.jta.bitronix.datasource.ignore-recovery-failures=false # Whether
or not recovery failures should be ignored.
spring.jta.bitronix.datasource.isolation-level= # The default isolation
level for connections.
spring.jta.bitronix.datasource.local-auto-commit= # The default
auto-commit mode for local transactions.
spring.jta.bitronix.datasource.login-timeout= # Timeout, in seconds,
for establishing a database connection.
spring.jta.bitronix.datasource.max-idle-time=60 # The time, in seconds,
after which connections are cleaned up from the pool.
spring.jta.bitronix.datasource.max-pool-size=10 # The maximum size of
the pool. 0 denotes no limit.
spring.jta.bitronix.datasource.min-pool-size=0 # The minimum size of
the pool.
spring.jta.bitronix.datasource.prepared-statement-cache-size=0 # The
target size of the prepared statement cache. 0 disables the cache.
spring.jta.bitronix.datasource.share-transaction-connections=false #
Whether or not connections in the ACCESSIBLE state can be shared within
the context of a transaction.
spring.jta.bitronix.datasource.test-query= # SQL query or statement
used to validate a connection before returning it.
spring.jta.bitronix.datasource.two-pc-ordering-position=1 # The
position that this resource should take during two-phase commit (always
first is Integer.MIN_VALUE, always last is Integer.MAX_VALUE).
spring.jta.bitronix.datasource.unique-name=dataSource # The unique name
used to identify the resource during recovery.
spring.jta.bitronix.datasource.use-tm-join=true Whether or not TMJOIN
should be used when starting XAResources.

@SpringBootApplicationpublic class JpaApplication { public static void main(String[] args) { SpringApplication.run(JpaApplication.class, args); }}

AUTO-CONFIGURATION

spring.autoconfigure.exclude= # Auto-configuration classes to exclude.

EMBEDDED MONGODB (EmbeddedMongoProperties)

spring.mongodb.embedded.features=SYNC_DELAY # Comma-separated list of
features to enable.
spring.mongodb.embedded.version=2.6.10 # Version of Mongo to use.

早晚这里只有 @SpringBootApplication 值得商量,走入@SpringBootApplication 的源码:

SPRING CORE

spring.beaninfo.ignore=true # Skip search of BeanInfo classes.

REDIS (RedisProperties)

spring.redis.database=0 # Database index used by the connection
factory.
spring.redis.host=localhost # Redis server host.
spring.redis.password= # Login password of the redis server.
spring.redis.pool.max-active=8 # Max number of connections that can be
allocated by the pool at a given time. Use a negative value for no
limit.
spring.redis.pool.max-idle=8 # Max number of “idle” connections in the
pool. Use a negative value to indicate an unlimited number of idle
connections.
spring.redis.pool.max-wait=-1 # Maximum amount of time (in
milliseconds) a connection allocation should block before throwing an
exception when the pool is exhausted. Use a negative value to block
indefinitely.
spring.redis.pool.min-idle=0 # Target for the minimum number of idle
connections to maintain in the pool. This setting only has an effect if
it is positive.
spring.redis.port=6379 # Redis server port.
spring.redis.sentinel.master= # Name of Redis server.
spring.redis.sentinel.nodes= # Comma-separated list of host:port
pairs.
spring.redis.timeout=0 # Connection timeout in milliseconds.


========================================

ca88亚洲城网站 14@SpringBootApplication
源码

SPRING CACHE (CacheProperties)

spring.cache.cache-names= # Comma-separated list of cache names to
create if supported by the underlying cache manager.
spring.cache.ehcache.config= # The location of the configuration file
to use to initialize EhCache.
spring.cache.guava.spec= # The spec to use to create caches. Check
CacheBuilderSpec for more details on the spec format.
spring.cache.hazelcast.config= # The location of the configuration file
to use to initialize Hazelcast.
spring.cache.infinispan.config= # The location of the configuration
file to use to initialize Infinispan.
spring.cache.jcache.config= # The location of the configuration file to
use to initialize the cache manager.
spring.cache.jcache.provider= # Fully qualified name of the
CachingProvider implementation to use to retrieve the JSR-107 compliant
cache manager. Only needed if more than one JSR-107 implementation is
available on the classpath.
spring.cache.type= # Cache type, auto-detected according to the
environment by default.

INTEGRATION PROPERTIES


========================================

SpringBoot 运营的时候加载主配置类,开启了电动配置效应
@EnableAutoConfiguration,再步向 @EnableAutoConfiguration 源码:

SPRING CONFIG – using environment property only (ConfigFileApplicationListener)

spring.config.location= # Config file locations.
spring.config.name=application # Config file name.

ACTIVEMQ (ActiveMQProperties)

spring.activemq.broker-url= # URL of the ActiveMQ broker.
Auto-generated by default. For instance tcp://localhost:61616
spring.activemq.in-memory=true # Specify if the default broker URL
should be in memory. Ignored if an explicit broker has been specified.
spring.activemq.password= # Login password of the broker.
spring.activemq.pooled=false # Specify if a PooledConnectionFactory
should be created instead of a regular ConnectionFactory.
spring.activemq.user= # Login user of the broker.

ca88亚洲城网站 15@EnableAutoConfiguration
源码

HAZELCAST (HazelcastProperties)

spring.hazelcast.config= # The location of the configuration file to
use to initialize Hazelcast.

ARTEMIS (ArtemisProperties)

spring.artemis.embedded.cluster-password= # Cluster password. Randomly
generated on startup by default.
spring.artemis.embedded.data-directory= # Journal file directory. Not
necessary if persistence is turned off.
spring.artemis.embedded.enabled=true # Enable embedded mode if the
Artemis server APIs are available.
spring.artemis.embedded.persistent=false # Enable persistent store.
spring.artemis.embedded.queues= # Comma-separated list of queues to
create on startup.
spring.artemis.embedded.server-id= # Server id. By default, an
auto-incremented counter is used.
spring.artemis.embedded.topics= # Comma-separated list of topics to
create on startup.
spring.artemis.host=localhost # Artemis broker host.
spring.artemis.mode= # Artemis deployment mode, auto-detected by
default. Can be explicitly set to “native” or “embedded”.
spring.artemis.port=61616 # Artemis broker port.

开掘最要害的正是 @Import(AutoConfigurationImportSelector.class)
那一个注脚,个中的 AutoConfigurationImportSelector 类的效果与利益就是往 Spring
容器中程导弹入组件,大家再进来那个类的源码,开掘有那多少个措施:

JMX

spring.jmx.default-domain= # JMX domain name.
spring.jmx.enabled=true # Expose management beans to the JMX domain.
spring.jmx.server=mbeanServer # MBeanServer bean name.

SPRING BATCH (BatchProperties)

spring.batch.initializer.enabled=true # Create the required batch
tables on startup if necessary.
spring.batch.job.enabled=true # Execute all Spring Batch jobs in the
context on startup.
spring.batch.job.names= # Comma-separated list of job names to execute
on startup (For instance job1,job2). By default, all Jobs found in the
context are executed.
spring.batch.schema=classpath:org/springframework/batch/core/schema-@@platform@@.sql
# Path to the SQL file to use to initialize the database schema.
spring.batch.table-prefix= # Table prefix for all the batch meta-data
tables.

/*** 方法用于给容器中导入组件**/@Overridepublic String[] selectImports(AnnotationMetadata annotationMetadata) { if (!isEnabled(annotationMetadata)) { return NO_IMPORTS; } AutoConfigurationMetadata autoConfigurationMetadata = AutoConfigurationMetadataLoader .loadMetadata(this.beanClassLoader); AutoConfigurationEntry autoConfigurationEntry = getAutoConfigurationEntry( autoConfigurationMetadata, annotationMetadata); // 获取自动配置项 return StringUtils.toStringArray(autoConfigurationEntry.getConfigurations;}// 获取自动配置项protected AutoConfigurationEntry getAutoConfigurationEntry( AutoConfigurationMetadata autoConfigurationMetadata, AnnotationMetadata annotationMetadata) { if (!isEnabled(annotationMetadata)) { return EMPTY_ENTRY; } AnnotationAttributes attributes = getAttributes(annotationMetadata); List < String > configurations = getCandidateConfigurations(annotationMetadata, attributes); // 获取一个自动配置 List ,这个 List 就包含了所有自动配置的类名 configurations = removeDuplicates(configurations); Set < String > exclusions = getExclusions(annotationMetadata, attributes); checkExcludedClasses(configurations, exclusions); configurations.removeAll(exclusions); configurations = filter(configurations, autoConfigurationMetadata); fireAutoConfigurationImportEvents(configurations, exclusions); return new AutoConfigurationEntry(configurations, exclusions);}// 获取一个自动配置 List ,这个 List 就包含了所有的自动配置的类名protected List < String > getCandidateConfigurations(AnnotationMetadata metadata, AnnotationAttributes attributes) { // 通过 getSpringFactoriesLoaderFactoryClass 获取默认的 EnableAutoConfiguration.class 类名,传入 loadFactoryNames 方法 List < String > configurations = SpringFactoriesLoader.loadFactoryNames( getSpringFactoriesLoaderFactoryClass(), getBeanClassLoader; Assert.notEmpty(configurations, "No auto configuration classes found in META-INF/spring.factories. If you " + "are using a custom packaging, make sure that file is correct."); return configurations;}// 默认的 EnableAutoConfiguration.class 类名protected Class<?> getSpringFactoriesLoaderFactoryClass() { return EnableAutoConfiguration.class;}

发表评论

电子邮件地址不会被公开。 必填项已用*标注