SpringBoot-----依赖工程取不到配置信息

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhangminemail/article/details/83551961

1、工程A取不到本身的配置信息????

2、显示结果为null

package com.imooc.config;

import java.net.MalformedURLException;
import java.net.URL;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import com.googlecode.jsonrpc4j.spring.AutoJsonRpcClientProxyCreator;
import com.imooc.api.ProductRpc;


@Configuration
@ComponentScan(basePackageClasses={ProductRpc.class})
@EnableConfigurationProperties(RpcProperties.class)
public class RpcConfig {
	
	@Resource
	private RpcProperties rpcProperties;
	
	private static Logger log = LoggerFactory.getLogger(RpcConfig.class);
//	@Value("${rpc.manager.url}") String url;
	@Bean
	public AutoJsonRpcClientProxyCreator rpcClientProxyCreator(@Value("${rpc.manager.url}") String url){
		AutoJsonRpcClientProxyCreator creator = new AutoJsonRpcClientProxyCreator();
		try {
			creator.setBaseUrl(new URL(url));
		} catch (MalformedURLException e) {
			log.error("创建rpc服务地址错误", e);
			e.printStackTrace();
		}
		creator.setScanPackage(ProductRpc.class.getPackage().getName());//扫描rpc所在包
		
		return creator;
	}
	
}

RpcProperties .java

package com.imooc.config;

import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties(prefix="rpc.manager")
public class RpcProperties {

	private String url;
	private String basePackage;
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	public String getBasePackage() {
		return basePackage;
	}
	public void setBasePackage(String basePackage) {
		this.basePackage = basePackage;
	}
	
}

猜你喜欢

转载自blog.csdn.net/zhangminemail/article/details/83551961
今日推荐