0

The question regards an endpoint that I want to make available only for demoing and should not be part of the project in production. Therefore I need to find a way of making the piece of code that reveals this endpoint available only when it should be.

I thought of using a different .properties file when it is needed, but this requires creating another one and changing the configuration and if there is a more simple way I would like to know.

Maybe building with a different Maven profile? Can I use the Maven profile name inside the code?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Noam_I
  • 7
  • 3
  • Related: https://stackoverflow.com/questions/4526113/java-conditional-compilation-how-to-prevent-code-chunks-from-being-compiled (different problem, but perhaps some of the proposed solutions can be useful) – Hulk Nov 16 '21 at 08:38
  • 1
    Are you using the Spring Framework or Spring Boot? It allows you to work with [profiles](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#features.profiles) for different environments (such as development, testing and production). Note, this is not the same as Maven profiles. – Jesper Nov 16 '21 at 08:40
  • Interesting. Seems to make more sense than playing with variables in the properties file. I will check it out. – Noam_I Nov 16 '21 at 08:45
  • Maybe using SPI and add the appropriate jar during the runtime on classpath... otherwise it's not there so it can't be used/accessed. – khmarbaise Nov 16 '21 at 09:43
  • If using Springboot, https://stackoverflow.com/questions/29958231/can-a-spring-boot-restcontroller-be-enabled-disabled-using-properties – JCompetence Nov 16 '21 at 21:58

0 Answers0