spring cloud config-server .properties content-negotiation failing

mawi

For me the content-negotiation mechanism of the e.g. for .properties is not working in Spring Cloud Config Server after switching to Spring Cloud Brixton.RC1 or Brixton.RC2 from Angel.SR5 and Angel.SR6.

The problem occurs when im starting the service using gradlew bootRun or java -jar .... It's working in my integration tests though (see Working Integration-Test below).

Usage Scenario:

I want to access the configuration in profile testing of application my-service, so I'm calling http://localhost:8888/my-service/testing.properties.

Expected result:

some.property=1234
some.other.property=hello there

Actual result:

Without Accept-Header:

<!DOCTYPE html>
<html>
    <head>
        <title>Error 406</title>
    </head>
    <body>
        <h1>Error 406: Not Acceptable</h1>
        <br/>
        Could not find acceptable representation
    </body>
</html>

With Accept-Header application/json:

{
    "timestamp": 1461140158009,
    "status": 406,
    "error": "Not Acceptable",
    "exception": "org.springframework.web.HttpMediaTypeNotAcceptableException",
    "message": "Could not find acceptable representation",
    "path": "/config/my-service/default.properties"
}

As you tell from the example, the content-negotiation mechanism seems to be working for error-handling but for the configuration access it is not.

Working Integration-Test:

I wrote the following Spock-Test

@WebIntegrationTest({"server.port=0", "management.port=0"})
@ActiveProfiles("testing")
@ContextConfiguration(loader = SpringApplicationContextLoader.class, classes = ConfigurationServiceApplication.class)
class ConfigurationAccessTest extends Specification {

    @Autowired
    TestserverInfo testserverInfo

    def "testing profile returns testing properties"() {
        given:
        RestTemplate rest = new TestRestTemplate(null, null)
        Properties properties = new Properties()

        when:
        String result = rest.getForObject( testserverInfo.getBasePath() + "/my-service-testing.properties", String.class );
        properties.load( new StringReader(result) )

        then:
        properties['test'] == 'Testing Profile World'
        properties['my.long.testing.property'] == 'Testing Profile Property'
    }

Things I already did so far:

  1. Wrote a the above Spock-Test for this scenario that is working in all noted versions of Spring Cloud Config Server
  2. Check ConfigServerMvcConfiguration for any obvious configuration errors as far as my knowledge of content-negotiation in Spring MVC went
  3. Provide a WebMvcConfigurer myself and initializing content-negotiation as in the configuration class referenced above:

    @EnableWebMvc
    @Configuration
    public class ConfigMvcConfiguration extends WebMvcConfigurerAdapter {
        private final Logger logger =  LoggerFactory.getLogger(ConfigMvcConfiguration.class);
    
        @Override
        public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
            configurer.mediaType("properties", MediaType.valueOf("text/plain"));
            configurer.mediaType("yml", MediaType.valueOf("text/yaml"));
            configurer.mediaType("yaml", MediaType.valueOf("text/yaml"));
            logger.info("media-types added");
        }
    }
    

Can anyone reproduce this issue or provide me any guidance on how to resolve it?

mawi

After all the ruckus with writing the question I realized: I was hunting a ghost. While checking the integration-test I wrote myself I found out, that I was trying to access the properties using a wrong url-schema.

TLDR

I was trying to access the properties using the URL

http://localhost:8888/config/my-service/testing.properties   <-- wrong
rather than
http://localhost:8888/config/my-service-testing.properties   <-- correct

Details

One can access the properties in JSON format using the following url schema (when not using labels):

http://<host>:<port>/<contextPath>/<application>/<profile>

If one wants to access the properties in a format other than json, she has to use another url-schema (again example without labels)

http://<host>:<port>/<contextPath>/<application>-<profile>.<format>

with format beeing properties/yml/yaml as currently supported formats.

Once again a small mistake that can complicate things alot.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Spring Cloud Config: define server config properties programmatically

From Dev

Save Properties Downloaded from Spring Cloud Config Server

From Dev

Should I mock Spring Cloud Config server properties during tests?

From Dev

Shared properties with Spring Cloud Config

From Dev

Shared properties with Spring Cloud Config

From Dev

Spring Cloud Config and static content

From Dev

Spring boot controller content negotiation

From Dev

Externalizing Spring Cloud Data Flow Config - Spring Cloud Config Server

From Dev

Externalizing Spring Cloud Data Flow Config - Spring Cloud Config Server

From Dev

microservice doesn't fetch properties from spring-cloud-config-server microservice

From Dev

Spring cloud config server - more than 1 properties file per app

From Dev

Spring Cloud Config Server without Spring Boot

From Dev

Spring MVC Content Negotiation throwing ClassCastException

From Dev

How to Use Content Negotiation in Spring Data Rest?

From Dev

How to disable content negotiation for Spring Actuators?

From Dev

Is there a simple way to solve content negotiation in Spring boot

From Dev

How to Use Content Negotiation in Spring Data Rest?

From Dev

Spring Cloud Config Client not fetching config when Spring Security is active on Spring Cloud Config Server

From Dev

Spring Cloud Config Server - Security Details

From Dev

Spring Cloud Config Server - Placeholder Label

From Dev

Disable Spring Cloud Server Config using profile?

From Dev

Pattern matching for profile in Spring Cloud Config Server

From Dev

Spring Cloud Config Server plain text

From Dev

Modify spring cloud config server in the client

From Dev

Configuring Spring Cloud Config Server and Spring Cloud Vault for production

From Dev

Include common config for multiple apps in Spring Cloud Config server

From Dev

spring cloud config client not loading configuration from config server

From Dev

Fetching properties from spring cloud config repo with sub folders

From Dev

What is the loading precedence for properties from Spring Cloud Config?

Related Related

  1. 1

    Spring Cloud Config: define server config properties programmatically

  2. 2

    Save Properties Downloaded from Spring Cloud Config Server

  3. 3

    Should I mock Spring Cloud Config server properties during tests?

  4. 4

    Shared properties with Spring Cloud Config

  5. 5

    Shared properties with Spring Cloud Config

  6. 6

    Spring Cloud Config and static content

  7. 7

    Spring boot controller content negotiation

  8. 8

    Externalizing Spring Cloud Data Flow Config - Spring Cloud Config Server

  9. 9

    Externalizing Spring Cloud Data Flow Config - Spring Cloud Config Server

  10. 10

    microservice doesn't fetch properties from spring-cloud-config-server microservice

  11. 11

    Spring cloud config server - more than 1 properties file per app

  12. 12

    Spring Cloud Config Server without Spring Boot

  13. 13

    Spring MVC Content Negotiation throwing ClassCastException

  14. 14

    How to Use Content Negotiation in Spring Data Rest?

  15. 15

    How to disable content negotiation for Spring Actuators?

  16. 16

    Is there a simple way to solve content negotiation in Spring boot

  17. 17

    How to Use Content Negotiation in Spring Data Rest?

  18. 18

    Spring Cloud Config Client not fetching config when Spring Security is active on Spring Cloud Config Server

  19. 19

    Spring Cloud Config Server - Security Details

  20. 20

    Spring Cloud Config Server - Placeholder Label

  21. 21

    Disable Spring Cloud Server Config using profile?

  22. 22

    Pattern matching for profile in Spring Cloud Config Server

  23. 23

    Spring Cloud Config Server plain text

  24. 24

    Modify spring cloud config server in the client

  25. 25

    Configuring Spring Cloud Config Server and Spring Cloud Vault for production

  26. 26

    Include common config for multiple apps in Spring Cloud Config server

  27. 27

    spring cloud config client not loading configuration from config server

  28. 28

    Fetching properties from spring cloud config repo with sub folders

  29. 29

    What is the loading precedence for properties from Spring Cloud Config?

HotTag

Archive