Nee*_*vas 2 configuration centralized spring-boot
无法使用“ http://localhost:9001/refresh ”刷新配置文件。如果我重新启动客户端应用程序,更新的配置加载良好。以下是我用来测试相同的简单休息控制器。刷新是使用 curl 命令“curl -d {} localhost:9001/refresh/”运行的,它给出了 404 错误。
@RestController
@RefreshScope
class ExampleController {
@Value("${Message2}")
private String message2 = "Hello World";
@RequestMapping
public String sayValue() {
return message2;
}
}
Run Code Online (Sandbox Code Playgroud)
以下是我正在使用的 pom.xml
<groupId></groupId>
<artifactId>MyConfigurationClient</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>MyConfigurationServer</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</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>Finchley.M8</spring-cloud.version>
</properties>
<dependencies>
<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>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
Run Code Online (Sandbox Code Playgroud)
小智 5
应在 pom.xml 中添加 Actuator 依赖项以使用。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
通过在 application.properties 或 bootstrap.properties 中添加以下条目来包含刷新端点。
management.endpoints.web.exposure.include=refresh
Run Code Online (Sandbox Code Playgroud)
调用刷新端点以重新加载属性而不重新启动应用程序。 http://localhost:8080/actuator/refresh(使用http post方法得不到)
@ConfigurationProperties - 将使用执行器刷新调用本身重新加载相应的属性。
@Value - 将在启动时加载属性,并且不会通过刷新调用重新加载。- 要重新加载用@Value 注释的属性,您需要,
| 归档时间: |
|
| 查看次数: |
5469 次 |
| 最近记录: |