I am using sql server to store properties. I want to store properties in two different database. One database for dev environment and other for Prod environment. How to configure this at config server application.properties.
currently I am getting dev properties from jdbc:sqlserver://mnkdevelopment:1433;databaseName=config; I want to get from prod properties in jdbc:sqlserver://mnkprod:1433;databaseName=config;
My current application.properties
server.port=8888 spring.profiles.active=jdbc spring.cloud.config.server.jdbc.sql=select keyName,value from properties where application=? and profile=? and label=? spring.cloud.config.server.jdbc.order=1 spring.datasource.url=jdbc:sqlserver://mnkdevelopment:1433;databaseName=config; spring.datasource.username=user spring.datasource.password=password spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
Comment From: ryanjbaxter
Perhaps the easiest way to do this is to have separate configs or dev and prod and activate them via a profile
Comment From: mnk-OneThing
I tired doing that created application-dev.properties and started config server with -Dspring.profiles.active=dev application-dev.properties
server.port=8888 spring.profiles.active=jdbc spring.cloud.config.server.jdbc.sql=select keyName,value from properties where application=? and profile=? and label=? spring.cloud.config.server.jdbc.order=1 spring.datasource.url=jdbc:sqlserver://mnkdevelopment:1433;databaseName=config; spring.datasource.username=mnk spring.datasource.password=413 spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
pom.xml
spring-boot-starter-parent;2.5.2
Getting below error not sure what I am missing.
ERROR org.springframework.boot.SpringApplication - Application run failed org.springframework.boot.context.config.InvalidConfigDataPropertyException: Property 'spring.profiles.active' imported from location 'class path resource [application-dev.properties]' is invalid in a profile specific resource [origin: class path resource [application-dev.properties] - 2:24] at org.springframework.boot.context.config.InvalidConfigDataPropertyException.lambda$throwOrWarn$1(InvalidConfigDataPropertyException.java:125) at java.lang.Iterable.forEach(Iterable.java:75) at java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1082) at org.springframework.boot.context.config.InvalidConfigDataPropertyException.throwOrWarn(InvalidConfigDataPropertyException.java:122) at org.springframework.boot.context.config.ConfigDataEnvironment.checkForInvalidProperties(ConfigDataEnvironment.java:361) at org.springframework.boot.context.config.ConfigDataEnvironment.applyToEnvironment(ConfigDataEnvironment.java:325) at org.springframework.boot.context.config.ConfigDataEnvironment.processAndApply(ConfigDataEnvironment.java:233) at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:102) at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:94) at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEnvironmentPreparedEvent(EnvironmentPostProcessorApplicationListener.java:102) at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEvent(EnvironmentPostProcessorApplicationListener.java:87) at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131) at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:82) at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:63) at java.util.ArrayList.forEach(ArrayList.java:1259) at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:117) at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:111) at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:62) at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:374) at org.springframework.boot.SpringApplication.run(SpringApplication.java:332) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332) at com.mnk.configserver.configserver.ConfigserverApplication.main(ConfigserverApplication.java:13)
Comment From: ryanjbaxter
remove spring.profiles.active=jdbc
and use Dspring.profiles.active=dev,jdbc
Comment From: mnk-OneThing
Thanks a lot @ryanjbaxter I am able to connect now.