【发布时间】:2017-12-21 21:35:22
【问题描述】:
我有一个 Spring Boot 应用程序。我需要将 spring boot 配置文件连接到 maven 配置文件,而不是当我调用命令时
mvn clean install -Pdev
或
mvn clean install -Pprod
它应该调用 spring boot 来加载 application-dev.yml 或 application-prod.yml。当我打电话时
mvn clean install
它应该在启动前调用 application-dev.yml 文件。所以spring boot dev profile需要从2个命令中调用。每次我切换配置文件时都会遇到问题,它会从默认配置文件构建应用程序。所以你能帮我连接 maven 和 spring boot 配置文件吗? 这是我的 pom.xml
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
<profiles>${spring-profiles}</profiles>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>dev</id>
<properties>
<spring-profiles>dev</spring-profiles>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<spring-profiles>prod</spring-profiles>
</properties>
</profile>
</profiles>
这是 application.yml 示例。
spring:
devtools:
restart :
enabled: true
livereload:
enabled: false
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
database: MYSQL
show_sql: true
properties:
hibernate.cache.use_second_level_cache: true
hibernate.cache.use_query_cache: false
hibernate.generate_statistics: true
hibernate.cache.region.factory_class: org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
hibernate:
ddl-auto: update
server:
port: 8080
compression:
enabled: true
mime-types : application/json,application/xml,text/html,text/xml,text/plain,application/javascript,text/css,text/html
session :
timeout : 540000
mail:
smtp:
starttls.enable: true
auth: true
port: 587
activation:
expiration.hours: 24
template: /mails/activationEmail.html
change-password:
template: /mails/passwordResetEmail.html
application-dev.yml、application-prod.yml 的区别仅在于端口。这样我只有在部署前更改 mvn 配置文件时才更改端口。
【问题讨论】:
标签: java spring maven spring-boot spring-boot-maven-plugin