spring-cloud / spring-cloud-config

External configuration (server and client) for Spring Cloud
Apache License 2.0
1.95k stars 1.29k forks source link

can spring cloud config storing xml file? #1044

Open shouwangqing opened 6 years ago

shouwangqing commented 6 years ago
shouwangqing commented 6 years ago

I am a Chinese, the stack overflow may be forbidden by our country and I cannot connect to it, so I go here to ask some questions.

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

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <property name="ENCODER_PATTERN" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{25} %M %L - %msg%n" />
    <springProperty scope="context" name="LOG-NAME" source="spring.application.name" />

    <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>

</configuration>
shouwangqing commented 6 years ago

@spencergibb the spring cloud config still cannot support the xml file now?

shouwangqing commented 6 years ago

I have read the issue about plain text file, and you say Loading plain text files (including xml) is supported. but I cannot load it, why? my config-client's config is 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/
shouwangqing commented 6 years ago

if spring cloud config only supports the properties file ,there maybe much limits of it. because some config cannot transfer to properties file

shouwangqing commented 6 years ago

@gjwilk01 I now have a problem like you, do you know how to solve it

djangofan commented 6 years ago

I've seen that sort of issue before with loading XML file if the file is prefixed with incorrect BOM element. Perhaps that is all this is?