Search code examples
springswaggerspring-cloud

Spring cloud server prefix cause error 404


I have Spring cloud server that configured as follows:

# Spring
spring.cloud.config.server.native.searchLocations=file:/data/config/
spring.jmx.default-domain=${spring.application.name}
endpoints.jmx.domain=${spring.application.name}
endpoints.jmx.unique-names=true
spring.profiles.active=native
spring.profiles.include=prod,machine
info.app.name=${spring.application.name}
spring.mvc.servlet.load-on-startup=1

# Config server
ms-configuration.config.path=/data/config/
ms-configuration.profile.default=prod
ms-configuration.backup.fullPath=/home/afa/msConfigBackup.zip

# Logging
logging.file=/data/algosec-ms/logs/${spring.application.name}.log

#Endpoints
management.endpoints.web.exposure.include=health,info,backup,restore
management.endpoints.web.base-path=/

And it works just fine. I am trying to add new rest controllers for the server in order to support swagger. Yet all the rest calls are automatically identified as configuration requests. So I added to the application.properties file the prefix option:

spring.cloud.config.server.prefix=/config

And now all the rest responses are

{"timestamp":"2020-01-09T11:31:22.063+0000","status":404,"error":"Not Found","message":"No message available","path":"/ms-configuration/config"}

I have tried the following curls and got the same result.

curl -X GET http://localhost:8082/ms-configuration/config/swagger/

curl -X GET http://localhost:8082/ms-configuration/config/

curl -X GET http://localhost:8082/ms-configuration/config/app_a

What can I do in order to keep my Spring cloud server as a configuration server and also a rest API controller?

Thanks!


Solution

  • You need to change the curl to:

    curl -X GET http://localhost:8082/config/ms-configuration/swagger/
    
    curl -X GET http://localhost:8082/config/ms-configuration/
    
    curl -X GET http://localhost:8082/config/ms-configuration/app_a
    

    As the spring.cloud.config.server.prefix is a prefix which is added in front of the url. (assuming you do not have a context path)