0

I have spring boot applications deployed on AWS. These applications have shared properties that are used to initialize database connection(Autowired properties), and they also have their own properties.

What we are doing now is setting application specific properties to application.properties. And, we have a class, which is extended by the Application class, has a static piece to load all the properties from S3.

Here's the base application

public abstract class BaseApp {
    static {
        /*
        logic to read properties from S3, and set to System.property
        */
        final GetObjectRequest request = new GetObjectRequest(bucketName, key);
        final S3Object s3obj = s3Client.getObject(request);
        final Properties prop = new Properties();
        prop.load(s3obj.getObjectContent());

        for (final Object k : prop.keySet()) {
            System.getProperties().put(k, prop.get(k));
        }
    }
}

For each of the services,

@SpringBootApplication
public class Application extends BaseApp {
    public static void main(final String[] args) {
        final SpringApplication app = new SpringApplication(Application.class);
        app.run(args);
    }
}

The problem here is, it also needs to connect to s3 when running UT code. Is there any solution to let the static piece to run only in production environment?

Bomin
  • 1,619
  • 5
  • 24
  • 39
  • Possible duplicate of [How to configure dynamic properties while using spring boot?](https://stackoverflow.com/questions/28756014/how-to-configure-dynamic-properties-while-using-spring-boot) – luboskrnac Oct 24 '18 at 09:55
  • If the class was a `@Component` or `@Configuration` then you could have used `@Profile("production")`. See [here](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-profiles) for more details. – Boris Oct 24 '18 at 11:13

0 Answers0