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?