1

we are now using the spring boot version is 1.5.13.RELEASE, and the spring cloud version is Edgware.SR3, and the spring cloud config version is 1.4.3.RELEASE。

And we use the eureka 1.7.2 as our registry center, and the config-server and the config-client is the eureka-client.

when we think that, since the spring cloud config is the config server and it should be manage any type of configs of our app. so we put the logback.xml to the github and refer to the spring cloud doc, the we can get the logback.xml in the config-client by setting the

 logging.config=${spring.cloud.config.uri}/*/default/master/logback.xml.

however, since the config-server and the config-client is the eureka-server's client, it should use the service name to communicate. and we set the config int the bootstrap.properties of the config-client like that:

spring.cloud.config.name=logback
spring.cloud.config.profile=default
spring.cloud.config.label=master
spring.cloud.config.discovery.enabled=true
spring.cloud.config.discovery.service-id=config-server-name
eureka.client.serviceUrl.defaultZone=http://admin:admin@localhost:7001/eureka/

but, when we start the config-client, the config-server occurs an error that:

java.lang.IllegalStateException: Failed to load property source from location 'file:/D:/others/test/configBack/qing-cloud-m1-config/logback-spring.xml'

Caused by: java.util.InvalidPropertiesFormatException: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 16; 文档根元素 "configuration" 必须匹配 DOCTYPE 根 "null"。
    at sun.util.xml.PlatformXmlPropertiesProvider.load(PlatformXmlPropertiesProvider.java:80)
    at java.util.Properties$XmlSupport.load(Properties.java:1201)
    at java.util.Properties.loadFromXML(Properties.java:881)
    at org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:136)
    at org.springframework.core.io.support.PropertiesLoaderUtils.loadProperties(PropertiesLoaderUtils.java:121)
    at org.springframework.boot.env.PropertiesPropertySourceLoader.load(PropertiesPropertySourceLoader.java:44)
    at org.springframework.boot.env.PropertySourcesLoader.load(PropertySourcesLoader.java:128)
    at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.doLoadIntoGroup(ConfigFileApplicationListener.java:490)
    at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadIntoGroup(ConfigFileApplicationListener.java:473)
    ... 87 common frames omitted

so how can I solved this problem, and the spring cloud config cannot store xml or another type file? if so, there maybe much limits of it

I read the source code and found that it may be can load xml file but why that problems occurs public static void fillProperties(Properties props, Resource resource) throws IOException { InputStream is = resource.getInputStream(); try { String filename = resource.getFilename(); if (filename != null && filename.endsWith(XML_FILE_EXTENSION)) { props.loadFromXML(is); } else { props.load(is); } } finally { is.close(); } }

the logback.xml is below and it cloud be execute in a standalone spring boot project ```

<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
        <pattern>${ENCODER_PATTERN}</pattern>
    </encoder>
</appender>
<appender name="FILE-APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>../../log/${LOG-NAME}.%d{yyyy-MM-dd}.log</fileNamePattern>
    </rollingPolicy>
    <encoder>
        <pattern>${ENCODER_PATTERN}</pattern>
    </encoder>
</appender>
<logger name="cn.jz" additivity="false" level="DEBUG">
    <appender-ref ref="CONSOLE" />
    <appender-ref ref="FILE-APPENDER"/>
</logger>

<root level="DEBUG">
    <appender-ref ref="CONSOLE" />
</root>

```

shouwang
  • 31
  • 1
  • 4

1 Answers1

3

You can store any text file in git that is used as a storage of configuration for spring-cloud-config server, but Spring can automatically resolve only .properties and .yml. For fetching other file formats you should use Serving Plain Text feature what you are refferring to in the question.

But when you start using discovery service you cannot use property spring.cloud.config.uri because url is discovered automatically by eureka client. So next propery of logging.config is not valid:

logging.config=${spring.cloud.config.uri}/*/default/master/logback.xml

For fetching custom files from config-server we used discoveryClient, requested URL of config-server by name in @PostConstruct and downloaded manually. But for logger it will be too late, because logback needs its configuration at the bootstrap phase. After researching of similar problems I figured out that properties can be customized/set during Bootstrap phase: Customizing bootstrap property sources. So we resolved this by setting custom property of config-server-uri and logback was able to download its configuration file. More implementation details in my answer in stackOverflow.

nmyk
  • 1,582
  • 1
  • 8
  • 20
  • Thanks for your answer,@nmyk, it seems that there is much limits of spring cloud config, the logback.xml id only one of my examples, if I want to integrate the dubbo.properties, what should I do? – shouwang Jun 22 '18 at 02:08
  • Not sure that my comment will be helpful, have never worked with Dubbo. But you can take a look on https://github.com/apache/incubator-dubbo-spring-boot-project, looks like there all properties are managed in application.properties, so they will be fetched automatically. In case you have different system and want to use xml-configs and spring-cloud-config you probably should download them using your code as a regular file to the temp folder and then initialize the context (we used this approach with csv file from config-server). – nmyk Jun 22 '18 at 07:44