I am implementing the spring cloud config to externalise configurations in my application. I have spring boot application with property placeholder configurer already implemented in it. As later I have done changes related to spring cloud config, it is not reading the property files from the remote repository. It always reads from the static properties given in property placeholder configurer. How can I make spring cloud config to work along with property placeholder configurer? I want my application to read properties from remote repository as per profile given and override the property placeholder configurer values. Kindly help me with this issue. Thanks in advance!
Property placeholder configuration:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:application.properties" />
</bean>
<bean id="dtSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
<property name="url" value="**test_url**" />
</bean>
</beans>
Spring Cloud config application.properties:
spring.application.name=<appname>
spring.cloud.config.server.git.uri=https://github.com/{username}/test.git
spring.cloud.config.server.git.username=<username>
spring.cloud.config.server.git.password=<password>
profiles.active=${spring.profiles.active}
spring.cloud.config.server.bootstrap=true
spring.config.name=<appname>
I have written one controller to check whether it's reading properties from remote repository.
@RefreshScope
@RestController
class HelloController {
@Value("${db.url:Hello default}")
private String message;
@RequestMapping("/message")
String getMessage() {
return this.message;
}
}
When I run and check for db url, it always returns "test_url" which is given in Property placeholder configuration and it do not read from the remote repository.
Let me know if I am missing something to get it working or else if it is not possible to combine both Spring cloud config and property placeholder configurer.