SpringBoot-----依賴工程取不到配置資訊
阿新 • • 發佈:2018-12-31
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; } }