Reputation: 60
I have a multi-module project, consider A as my library project and B as an implementation project that imports A. Now my DataSource is configured in B using @Configuration
and getDataSource()
method dynamically. I want to access a property from this dynamically configured DataSource in project A from project B. I tried using @ConfigurationProperties
but it is not possible. Is there any way to achieve this?
Thanks in advance!
Upvotes: 0
Views: 385
Reputation: 197
You could try inject Environment into this service:
private Environment env;
and then
env.getProperty("b.datasource.url");
or inject ApplicationContext:
private ApplicationContext context;
and then get whole bean:
context.getBean(DataSource.class);
or by name:
context.getBean("BDataSource"); // <- you need to know proper bean name
Upvotes: 0
Reputation: 1060
While configuring your DataSource, add a System property like System.setProperty("key", value);
and access it in your library like System.getProperty("key");
Upvotes: 1