我正在实施一个Spring云应用程序,我正在为Windows环境配置配置服务器。我正在设置一个基于本机文件系统的配置服务器。我没有使用Git,所以我创建了一个本地文件结构。
配置服务器 application.properties 文件
server.port = 8208
spring.cloud.config.server.native.searchLocations = D:\Repository
spring.profiles.active=native
的pom.xml
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<version>1.0.0.RELEASE</version>
<relativePath />
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Dalston.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>
ConfigServer类 -
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
@SpringBootApplication
@EnableConfigServer
public class MicroserviceConfigServer {
public static void main(String[] args) {
SpringApplication.run(MicroserviceConfigServer.class, args);
}
}
当我运行应用程序时,它成功加载并在端口8208的tomcat服务器上运行。但问题在于存储库位置。我收到了http://localhost:8208/config/default/master
的回复{"name":"config","profiles":["default"],"label":"master","version":null,"state":null,"propertySources":[]}
但是我在存储库中有很多.properties文件,但其他服务也无法访问这些文件。请帮我解决这个问题。
答案 0 :(得分:0)
好像你在使用Windows。在这种情况下 - 尝试使用当前用户的主文件夹,因此将D:\Repository
更改为~/Repository
之类的内容。您的用户的主文件夹位于c:\Users\<YOUR USER NAME>
将您的配置放入此文件夹
另一种方法是在Spring Cloud Config的官方页面上使用注释:&#34;在Windows上,您需要额外的&#34; /&#34;在文件URL中,如果它是绝对的驱动器前缀&#34;