i have a Spring Boot application. I need to connect spring boot profile to maven profile so than when i am calling command
mvn clean install -Pdev
or
mvn clean install -Pprod
it should call spring boot to load application-dev.yml or application-prod.yml. And when i call
mvn clean install
it should call application-dev.yml file before startup. So spring boot dev profile needs to be called from 2 commands. I have a problem every time i switch profile it builds application from default profile. So can you please help me to wire maven and spring boot profile. Here is my 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>
Here is application.yml example.
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
Difference between application-dev.yml, application-prod.yml is only in port. So that I only change port when i change mvn profile before deploy.