分佈式disconf+spring5使用遇到重複加載的問題

 <aop:aspectj-autoproxy proxy-target-class="true"/>

    <!-- 使用disconf必須添加如下配置 -->
    <bean id="disconfMgrBean" class="com.baidu.disconf.client.DisconfMgrBean"
          destroy-method="destroy">
        <property name="scanPackage" value="com.tmall.flow.flowrule"/>
    </bean>

    <bean id="disconfMgrBean2" class="com.baidu.disconf.client.DisconfMgrBeanSecond"
          init-method="init" destroy-method="destroy">
    </bean>

    <!-- 使用託管方式的disconf配置(無代碼侵入, 配置更改會自動reload)-->
    <bean id="configproperties_disconf"
          class="com.baidu.disconf.client.addons.properties.ReloadablePropertiesFactoryBean">
        <property name="locations">
            <list>
                <value>activityrule.xml</value>
            </list>
        </property>
    </bean>

    <bean id="propertyConfigurer"
          class="com.baidu.disconf.client.addons.properties.ReloadingPropertyPlaceholderConfigurer">
        <property name="ignoreResourceNotFound" value="true"/>
        <property name="ignoreUnresolvablePlaceholders" value="true"/>
        <property name="propertiesArray">
            <list>
                <ref bean="configproperties_disconf"/>
            </list>
        </property>
    </bean>

disconf.xml配置如上,沒什麼大問題,按官方給的demo來好了java

配置類以下:web

import com.baidu.disconf.client.common.annotations.DisconfFile;
import org.springframework.stereotype.Service;
/**
 * 空的分佈式配置文件,用途有兩種:<br/>
 * 1. 對配置文件裏的內容不感興趣,只是單純的下載<br/>
 * 2. 當配置文件更新時,能夠自動下載到本地
 */
@Service
@DisconfFile(filename = "activityrule.xml")
public class ActivityRuleConfig {

}

配置類回調加載類spring

@Service
@DisconfUpdateService(classes = { ActivityRuleConfig.class})
public class ActivityRuleCallBack implements IDisconfUpdate {

    @Override
    public void reload() throws Exception {
        FlowXmlDom.parseXMLData("/activityrule.xml");
    }
}

 

main啓動類:app

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.example.disconf.demo.task.DisconfDemoTask;

/**
 * @author liaoqiqi
 * @version 2014-6-17
 */
public class DisconfDemoMain {

    protected static final Logger LOGGER = LoggerFactory.getLogger(DisconfDemoMain.class);

    private static String[] fn = null;

    // 初始化spring文檔
    private static void contextInitialized() {
        fn = new String[] {"applicationContext.xml"};
    }

    /**
     * @param args
     *
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {

        contextInitialized();
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(fn);

        DisconfDemoTask task = ctx.getBean("disconfDemoTask", DisconfDemoTask.class);

        int ret = task.run();

        System.exit(ret);
    }
}

maven中spring版本使用 maven

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>RELEASE</version>
</dependency>
最新爲5.0版本
啓動後老是會報錯,目前仍是頭一次使用spring5遇到問題,

Exception in thread "main" java.lang.NoSuchMethodError: com.baidu.disconf.client.addons.properties.DefaultPropertyPlaceholderConfigurer.parseStringValue(Ljava/lang/String;Ljava/util/Properties;Ljava/util/Set;)Ljava/lang/String;
    at com.baidu.disconf.client.addons.properties.ReloadingPropertyPlaceholderConfigurer.parseStringValue(ReloadingPropertyPlaceholderConfigurer.java:97)
    at com.baidu.disconf.client.addons.properties.ReloadingPropertyPlaceholderConfigurer$PlaceholderResolvingBeanDefinitionVisitor.resolveStringValue(ReloadingPropertyPlaceholderConfigurer.java:457)
    at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitBeanClassName(BeanDefinitionVisitor.java:107)
    at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitBeanDefinition(BeanDefinitionVisitor.java:80)
    at com.baidu.disconf.client.addons.properties.ReloadingPropertyPlaceholderConfigurer.processProperties(ReloadingPropertyPlaceholderConfigurer.java:382)
    at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:86)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:164)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:693)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:95)
    at com.example.disconf.demo.DisconfDemoMain.main(DisconfDemoMain.java:32)

 

反反覆覆覈對線上文檔,發現沒有問題分佈式

再一次集成到spring-web空項目中,仍是同樣報錯ide

[11:26:13:410] [WARN] - com.baidu.disconf.client.store.inner.DisconfCenterStore.storeOneFile(DisconfCenterStore.java:73) - There are two same fileName key!!!! activityrule.xml [11:26:13:443] [ERROR] - org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:321) - Context initialization failed java.lang.NoSuchMethodError: com.baidu.disconf.client.addons.properties.DefaultPropertyPlaceholderConfigurer.parseStringValue(Ljava/lang/String;Ljava/util/Properties;Ljava/util/Set;)Ljava/lang/String;
    at com.baidu.disconf.client.addons.properties.ReloadingPropertyPlaceholderConfigurer.parseStringValue(ReloadingPropertyPlaceholderConfigurer.java:97) ~[disconf-client-2.6.36.jar:?]
    at com.baidu.disconf.client.addons.properties.ReloadingPropertyPlaceholderConfigurer$PlaceholderResolvingBeanDefinitionVisitor.resolveStringValue(ReloadingPropertyPlaceholderConfigurer.java:457) ~[disconf-client-2.6.36.jar:?]
    at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitBeanClassName(BeanDefinitionVisitor.java:107) ~[spring-beans-5.0.2.RELEASE.jar:5.0.2.RELEASE]
    at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitBeanDefinition(BeanDefinitionVisitor.java:80) ~[spring-beans-5.0.2.RELEASE.jar:5.0.2.RELEASE]
    at com.baidu.disconf.client.addons.properties.ReloadingPropertyPlaceholderConfigurer.processProperties(ReloadingPropertyPlaceholderConfigurer.java:382) ~[disconf-client-2.6.36.jar:?]
    at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:86) ~[spring-beans-5.0.2.RELEASE.jar:5.0.2.RELEASE]
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284) ~[spring-context-5.0.2.RELEASE.jar:5.0.2.RELEASE]
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:164) ~[spring-context-5.0.2.RELEASE.jar:5.0.2.RELEASE]

 

我把spring的版本換回4.3.13.RELEASE,啓動不報錯了。post

這裏先記錄下,諸位大神看看是什麼問題,目前小弟趕項目進度,沒時間研究,放給你們看看spa

相關文章
相關標籤/搜索