I have a class with same name in the imported jar file.
JavaScript
x
@Configuration
@ConfigurationProperties(prefix = "queues")
public class QueueProperties {
String queuename;
String queuemanager;
//Rest code
}
The same class with the same properties also there in the jar file.
I have given bean definition in my configuration file for the jar bean.
JavaScript
@Bean
public com.jar.class.path getQueueProperties() {
return new com.jar.class.path.QueueProperties();
}
But when the application started it is using the properties of my bean class instead of the properties defined for jar class bean.
Property values are kept in application.yml file.
JavaScript
queue:
queueManager: 'queuemanager'
queuename: 'queuename'
jar:
class:
queue:
queueManager: 'queuemanager'
queuename: 'queuename'
I want to use properties defined in yml for jar file bean. Could there be any solution around this?
Advertisement
Answer
You can use Spring profile.
JavaScript
queue:
queueManager: 'queuemanager'
queuename: 'queuename'
---
spring:
profiles: jar
queue:
queueManager: 'queuemanager'
queuename: 'queuename'
You can use –spring.profiles.active=jar on command line to use your jar profile.
You should not use configuration as normal beans, do this:
JavaScript
@Configuration
public class MyConfiguration {
@Bean
@ConfigurationProperties(prefix = "queue")
public com.jar.class.path getQueueProperties() {
return new com.jar.class.path.QueueProperties();
}
}
public class QueueProperties {
String queuename;
String queuemanager;
//Rest code
}