我尝试使用Config Server实现spring外部配置。第一次启动应用程序时,它运行良好,但是对属性文件的任何更改均未反射(reflect)出来。我试图使用/refresh端点动态刷新我的属性,但似乎无法正常工作。在这方面的任何帮助将大有帮助。
我尝试过帐到localhost:8080/refresh,但收到404错误响应。
下面是我的应用程序类的代码
@SpringBootApplication
public class Config1Application {
public static void main(String[] args) {
SpringApplication.run(Config1Application.class, args);
}
}
@RestController
@RefreshScope
class MessageRestController {
@Value("${message:Hello default}")
private String message;
@RequestMapping("/message")
String getMessage() {
return this.message;
}
}
POM文件是
<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-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</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>
和bootstrap.properties
spring.application.name=xxx
spring.cloud.config.uri=https://xxxxxx.com
management.security.enabled=false
endpoints.actuator.enabled=true
最佳答案
现在,Spring 2及更高版本的端点为/actuator/refresh
。
来自评论:
management.endpoints.web.exposure.include=refresh
中设置bootstrap.properties/bootstrap.yml
注意:如果您不是
Spring-Cloud
的新手,并且不确定web.exposure
中可以使用的所有关键字,则可以将其设置为*
(management.endpoints.web.exposure.include=*
)以暴露所有内容,以后您可以了解端点及其限制。关于spring-cloud - @RefreshScope和/refresh无法正常工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49311068/