Search code examples
springspring-bootspring-mvcspring-websocket

Should path for REST api or destination for STOMP be part of spring boot application.properties?


I would like to know if it is good practise (or if it is even good idea at all) to put variables defining paths for REST endpoints and/or destination for STOMP over WS to spring boot application .properties or I should just write it directly to controller/simpMessagingTemplate?

On the one hand it would allow me to change it one one place but on the other I have never saw it used in any example or app in production.


Solution

  • It's a good practice to put the base URL and maybe the context path as properties in your client, because these can change even when the server code does not change.

    E.g. if your server runs locally with /rest as contextPath and /chat as STOMP endpoint, you would use:

    application-local.properties:
    serverBaseUrl = ws://localhost:8080/rest
    
    client.java:
    @Value("${serverBaseUrl}/chat")
    

    The names of the endpoint themselves (/chat), should be the names of the resources they represent. They should not change that often, unless there's a fundamental change in the API. And if that happens, you'll probably need to do more than just change the name in the client as well.