0

I need to use two *.properties file to determine config of Spring Boot application server. How can I set the second configuration path?

I use spring-boot-starter-parent version 1.5.10 and such *.properties file:

spring.datasource.url=url
spring.datasource.username=root
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=update
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialec
spring.jpa.properties.hibernate.current_session_context_class=
org.springframewok.orm.hibernate4.SpringSessionContext
spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true
spring.datasource.hikari.minimum-idle=5
spring.datasource.hikari.maximum-pool-size=10
spring.datasource.hikari.idle-timeout=30000

Now, I need to address database info from another properties file.

Edit: Note that I need to put second properties file outside of my WAR file in WEB-INF folder.

0

2 Answers 2

1

(1) This is best practices when switching between development mode and production environment.

https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-profiles.html#boot-features-profiles

Reference for version 1.5.10.RELEASE: https://docs.spring.io/spring-boot/docs/1.5.10.RELEASE/reference/htmlsingle/#boot-features-external-config-profile-specific-properties

For more specific, you create 3 files

application.properties for common properties.

application-dev.properties for only own properties what used in profile dev

application-production.properties for only own properties what used in profile production

(Notice: Has convention over naming)

Point profile what used, in application.properties has line spring.profiles.active=dev (in development) or spring.profiles.active=production (in production)

(2)

Note that I need to put second properties file outside of my WAR file in WEB-INF folder.

Assumption, your file is foo.properties. It is outside WAR file, it has not nature of Spring's properties file. Therefore, Spring Framework/Spring Boot can not read it automatically. You must write few lines of Java code to reading the content of foo.properties, then assign to configuration manually (see example configuration class)

Sign up to request clarification or add additional context in comments.

4 Comments

I just edit my question, please make me advice based on that note
Bear in mind: File *.properties outsite WAR file, it is not Spring's properties.
Ok man, Thanks I got it. now I should search how to set properties from code
Consider using spring.config.location (an alternative for config by Java code) Reference: docs.spring.io/spring-boot/docs/current/reference/html/…
0

You can access multiple of properties file using @PropertySource

Follow the following stackoverflow thread. https://stackoverflow.com/a/47178674/7538821

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.