Reputation: 351
I have a project setup something like this:
-common-lib (common lib to included by multiple services)
-event-lib (spring framework 4 (read IOC) library for our event buffer. I want to embed the prod configuration within the app so consumers can use it without configuring it.
-serviceA (depends on event-lib, springboot application)
-serviceB (depends on event-lib, spring framework application)
I've been struggling on how to manage configuration in a Java-annotated way.
In the example below (running in the event library as a spring framework 4 project):
I couldn't get the PropertySource to honor the enviornment's spring.profiles.active
The environment wouldn't set an active profile even though -Dspring.profiles.active="dev" was specified)
@Configuration
@ComponentScan(basePackages = "com.*")
@PropertySource("classpath:events-{$spring.profiles.active}.properties")
public class EventConfiguration {
@Inject
private ConfigurableApplicationContext ctx;
@Inject
private Environment environment;
@Value("${events.asset-processing-queue}")
private String assetProcessingEventQueue;
}
It didn't make much sense to me, since multiple profiles could be activated at once (and that approach to referencing files is dependent on having only 1 set active).
Ideally, I am trying to find a solution that:
Upvotes: 2
Views: 758
Reputation: 1053
Here's how we did it:
@PropertySource("classpath:/${env}.config.properties")
public class Application implements RequestHandler<Request, Object> {
@Override
public Object handleRequest(Request request, Context awsContext) {
ExecutionEnvironment env = getEnvironment(awsContext.getFunctionName());
System.setProperty("env", env.toString());
This respects the environment property.
Upvotes: 1