I have few spring boot projects:
proj-A
proj-B
proj-C
Now I have developed another spring project:
proj-common-ABC
In proj-common-ABC
I have externalised some common implementation of proj-A proj-B proj-C
and using proj-common-ABC
as maven dependency in proj-A proj-B proj-C
Now I want to read a property all.service.common.property = value
defined in proj-A proj-B proj-C
from proj-common-ABC
.
How can i achieve this please help
CodePudding user response:
class in proj-common-ABC
where we need to read the property
@Component
public class componentClass {
@Value("${all.service.common.property}")
private String property;
}
then we need to write a configuration class in our proj-A proj-B proj-C
@Configuration
@ComponentScan(basePackages = {"com.path.of.package"})
public class CommonABCComponentConfig {
}
This will read the classes marked with @Component annotation in the given packed and will load a bean into the application context. So there after using @Value annotation we can read the properties.