0

We have a Spring-Boot Web application currently deployed to 7 environments (DEV, SIT, UAT, Pre-Prod, Prod, etc.). This application connects to other REST services, which has different URLs for each of 7 environments and are maintained in environment specific property file for our application.

We are planning to reduce number of environments to 3 (DEV, Staging, Prod) for our application. So, in the non-prod environments, the consumers of our application will call staging environment of our app and pass an additional header in request telling us which environment they are calling from.

And, our app should call other REST service URLs specific to environment header in request.

I was thinking, we can create beans for each of the REST endpoints for each environment - for eg UserServiceDev, UserServiceUat, etc. And we create a factory class where these beans will be injected and based on the environment header, it can return appropriate bean.

But this will involve replacing all injected service beans with infecting beans of this factory and will require changes to lot of files.

Is there any easier and cleaner way to do this?

1
  • 3
    Make an API Gateway in between the app and the upstream REST services you call. Don't turn your app into an API Gateway or router. Separation of concerns!
    – Laiv
    Apr 13, 2021 at 13:06

1 Answer 1

1

Is it there a way to define those REST points with an application profile?

If yes, I would suggest to define an application.properties or application.yml where those endpoints are stored as environment variables and you define those variables in your actual environment.

This approach has as bonus the fact that you can also run your application in Containers and define those values in your preferred orchestration tool (docker-compose, Kubernetes)

Another approach might be that you define a base application profile and through the selection of a maven profile (assuming you are using maven here), you select the actual profile that has to be delivered with your application.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.