0

I would like to load different query xml files at runtime using configuration file (helm or .property). What I want to achieve is to load 1.xml when I am loading Oracle database and 2.xml when loading Azure SQL.

These databases (Oracle/Azure SQL) are loaded interchangeably, which means I am defining which database is loading in my configuration like this:

datasource.project.driverClassName='Oracle' //or 'SQLServerDriver'
datasource.project.url='OracleUrl' // or 'SQLUrl'

I want to add flag like datasource.project.dialect='Oracle' or something like that so I can indicate which database I am loading.

Once this is done, I want my repository class to load different xml files that contains different sql queries. But I am not sure how I can define this in the @PropertySource annotation. Here is example:

@Configuration
@Import(DataSourceConfig.class)
@PropertySource("classpath:event-sql-oracle.xml") //HOW DO I LOAD XML DYNAMICALLY USING THE FLAG?

So if flag says 'Oracle', I want to load "classpath:event-sql-oracle.xml" and if it says 'Azure SQL', I want to load "classpath:event-sql-Azure.xml". Is this achieveable?

Jonathan Hagen
  • 580
  • 1
  • 6
  • 29

1 Answers1

0

I found the answer. I just need to use placeholder for @PropertySource like this:

@PropertySource("classpath:event-sql-${dbtype}.xml")

then define dbtype in the configuration like .properties or helm.

Jonathan Hagen
  • 580
  • 1
  • 6
  • 29