在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java/ spring中xml文件配置的參數(shù)拿不到

spring中xml文件配置的參數(shù)拿不到

這是spring的xml配置文件

<bean id="zookeeperService"
        class="test.service.ZookeeperService">
        <property name="zookeeperHost" >
            <value>127.0.0.1</value>
        </property>
        <property name="zkPath" >
            <value>/limit_02</value>
        </property>
        <property name="applicationName" >
            <value>lbx</value>
        </property>
    </bean>

    <bean id="limitService"
        class="test.service.LimitService">
        <property name="url" >
            <value>http://127.0.0.1</value>
        </property>
    </bean>
    

這是ZookeeperService ,應(yīng)用啟動(dòng)的時(shí)候會(huì)走這里加載zookeeper一些配置這里就能拿到參數(shù),但是afterPropertiesSet這個(gè)方法不知道為什么會(huì)運(yùn)行兩次,第二次這些zkPath,applicationName,zookeeperHost就為null了

@Service
public class ZookeeperService implements InitializingBean {

    private String zkPath;
    private String applicationName;
    private String zookeeperHost;
    public void afterPropertiesSet() throws Exception {
        init();
        setActionInfo();
        initZkWatcher();
    }
    public String getZookeeperHost() {
        return zookeeperHost;
    }

    public void setZookeeperHost(String zookeeperHost) {
        this.zookeeperHost = zookeeperHost;
    }

    public String getApplicationName() {
        return applicationName;
    }

    public void setApplicationName(String applicationName) {
        this.applicationName = applicationName;
    }

    public String getZkPath() {
        return zkPath;
    }

    public void setZkPath(String zkPath) {
        this.zkPath = zkPath;
    }
}

這是LimitService,程序運(yùn)行到這里url就為null,拿不到不知道為什么

@Service
public class LimitService{
    private String url= null;
    public Map<String, Object> rateLimitAction(String actionName, String userCode) {
    Map<String, Object> reMap = new HashMap<String, Object>();
    paramMap.put("serverUrl ", url);
    return reMap;
}

    public String getRateLimitServerUrl() {
        return rateLimitServerUrl;
    }
    
    public void setRateLimitServerUrl(String rateLimitServerUrl) {
        this.rateLimitServerUrl = rateLimitServerUrl;
    }
}
回答
編輯回答
枕頭人

xml配置了一次,@Service又配置了一次。并且@Service配置的時(shí)候,屬性也沒有注入,當(dāng)然就是null了。xml和注解使用其中一個(gè)就好了

2018年4月2日 11:43