My schema names are different for Test and Prod environments. How to access them from properties file? I want to read the schema from the properties file based on the environment. Tried the link suggested by adding in datasource config but it is not working. The database is SQL server.
Asked
Active
Viewed 928 times
0
-
1please mention your requirement clearly. Or please look at the below link once. https://stackoverflow.com/questions/24278659/change-database-schema-used-by-spring-boot/24278772 – Ranjith Bokkala Jan 10 '20 at 05:47
-
are you using gradle or maven" – Popeye Jan 10 '20 at 08:05
-
i am using maven.. – Naveen Meka Jan 10 '20 at 08:29
1 Answers
0
you need to create a properties file for each profile (applications-test.properties and applications-prod.properties) and for each env you put your database configuration.
Make sure to use the right profile in your code.

Kamèl Romdhani
- 342
- 1
- 9
-
-
For Hibernate as JPA provider use: spring.jpa.properties.hibernate.default_schema=dbo For plain JDBC, add it to your connection string: jdbc:postgresql://localhost:5432/mydatabase?currentSchema=myschema – Kamèl Romdhani Jan 10 '20 at 08:43
-
okay, but for multiples schema how you'll provide. Tried this in config file props.put("Spring.jpa.properties.hibernate.default_schema","schemaname") but it is not working – Naveen Meka Jan 10 '20 at 08:44
-
you want multiple schema because you have multiple env right ? you want 1 schema per env ? – Kamèl Romdhani Jan 10 '20 at 08:46
-
-
-
Currently am using mulitple datasources but where to specify schema name for it – Naveen Meka Jan 10 '20 at 08:54
-
you add schema just like I showed you, multiple datasources, 1 schema per datasource means multiple schema – Kamèl Romdhani Jan 10 '20 at 09:07
-
Isn't this "Spring.jpa.properties.hibernate.default_schema" unique for properties file? – Naveen Meka Jan 10 '20 at 09:09
-
yes you use "Spring.jpa.properties.hibernate.default_schema" in a properties file – Kamèl Romdhani Jan 10 '20 at 09:14
-
-
yes exactly, 2 properties files, multiple datasources in each properties file means multiple schema for each env – Kamèl Romdhani Jan 10 '20 at 09:28
-
what you are suggesting is testschema1.props, testschema2.props, prodschema1.props, prodschema2.props ? – Naveen Meka Jan 10 '20 at 09:32