Java EnableConfigServer在spring引导中不适用于本机位置
我试图在spring boot中使用@EnableConfigServer为应用程序中的所有属性配置配置服务器。请参阅下面的代码:Java EnableConfigServer在spring引导中不适用于本机位置,java,spring,spring-boot,microservices,Java,Spring,Spring Boot,Microservices,我试图在spring boot中使用@EnableConfigServer为应用程序中的所有属性配置配置服务器。请参阅下面的代码: @EnableConfigServer @SpringBootApplication public class ConfigServerApplication { public static void main(String[] args) { SpringApplication.run(ConfigServerApplication.cl
@EnableConfigServer
@SpringBootApplication
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.cdk.config</groupId>
<artifactId>configserver</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>configserver</name>
<description>Contains all the configurations/properties required by all the services</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR1</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
已将所有属性文件复制到:/Users/Sankest/StarterProjects/MicroServices/AllConfigurations/
但是,当我尝试访问url时,我没有看到任何属性文件,并得到以下响应:
{"name":"config-server","profiles":["default"],"label":null,"version":null,"state":null,"propertySources":[]}
我不这样认为,您正在访问正确的端点 例如: 如果您的
AllConfigurations
文件夹中有三个文件
该文件可以是yml或properties
-
左侧的名称是应用程序名称,右侧的名称是概要文件
因此application-dev.yml的端点将是
从客户端访问配置服务器中的特定配置文件,需要设置活动配置文件
如果客户端应用程序名为test
spring.profile.active=dev
然后,它将从配置服务器向您的客户机返回testdev
文件
spring.cloud.config.server.native.searchLocations=file:///Users/Sankest/StarterProjects/MicroServices/AllConfigurations/
文件:后有3个前斜杠。即使不运行应用程序,验证路径是否正确的一种方法是在浏览器中粘贴路径并检查它是否显示所有文件application.yml
或application.properties
dev
,文件名应为application-dev.yml
或application-dev.properties
(如果所有文件都在同一文件夹中),然后将同时显示dev
和default
配置文件条目 <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
org.springframework.cloud
spring云配置服务器
您在哪个操作系统上运行应用程序?您可以尝试使用spring.cloud.config.server.native.searchLocations=file:/Users/Sankest/StarterProjects/MicroServices/AllConfigurations
?我想额外的/
就是问题所在。我正在使用mac并尝试删除额外的/。但这不起作用。您是否确实尝试过spring.cloud.config.server.native.searchLocations=file:/Users/Sankest/StarterProjects/MicroServices/AllConfigurations
?在文件:
后加一个斜杠。这对我来说也很好。
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>