我正在尝试学习如何使用spring cloud集中配置从服务器到客户端进行配置。 我在服务器上有一个application.yml文件,我希望从中获得一些属性。
application.yml
logging:
config: ${spring.cloud.config.uri}/logback-standard.xml
我没有在客户端应用程序中使用bootstrap.properties,而是在本地tomcat配置文件夹中配置了一个我在catalina.bat中调用的environment.cmd文件。在environment.cmd文件中,我设置了spring.cloud.config.uri。
catalina.bat中
call "C:\Program Files\Tomcat\8.0.24\environment.cmd"
environment.cmd
set JAVA_OPTS=%JAVA_OPTS% -Dspring.cloud.config.uri=http://configuration-dev:80/configuration_server
的pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<!--Spring Cloud-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
<version>1.2.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
CloudConfigApplication.java
@SpringBootApplication
public class CloudConfigApplication extends SpringBootServletInitialize{
public static void main(String[] args) {
SpringApplication.run(CloudConfigApplication.class, args);
}
}
CloudConfigController.java
@RestController
public class CloudConfigController {
@Value("${logging.config}")
public String config;
@RequestMapping(value="/log", method = RequestMethod.GET)
public String log(){
return config;
}
}
如果我直接从我的IDE运行它并配置了tomcat,那么它正在运行但是当我在项目上安装maven时,我收到此错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.cloudConfigController': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'logging.config' in string value "${logging.config}"
请帮我弄清楚如何解决这个问题。 提前谢谢。