Matthew Ward
Matthew Ward

Reputation: 351

Best approach to configuration management in spring framework for a project with multiple modules?

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):

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

Answers (1)

dvallejo
dvallejo

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

Related Questions