配置客户端无法从 Git 中已修改的属性文件中获取已更改的属性值。我需要帮助来解决这个问题。
我创建了一个新的 spring 配置服务器和客户端。最初从属性文件中获取的值是正确的。当我更改属性文件中的值时,客户端仍在返回旧值。我尝试发布到http://localhost:8080/actuator/refresh,即使在此之后,旧值也会返回。最后我从 git 存储库中删除了属性文件,客户端仍然返回旧值。
配置服务器 bootstrap.properties
spring.application.name=ConfigServer
server.port=8888
encrypt.key=123456
spring.security.user.password=configpassword123
spring.cloud.config.server.git.uri=https://some-repository/ConfigRepo.git
spring.cloud.config.server.git.username=git_user
spring.cloud.config.server.git.password=git_password
配置服务器.java
@Configuration
@EnableDiscoveryClient
@SpringBootApplication
@EnableConfigServer
public class ConfigServer {
public static void main(String[] args) {
SpringApplication.run(ConfigServer.class, args);
}
}
WebSecurityConfiguration.java
@Configuration
@EnableWebSecurity
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable().authorizeRequests()
.anyRequest().authenticated().and().httpBasic();
}
}
配置客户端 bootstrap.properties
spring.application.name=config-client
spring.cloud.config.uri=http://config-server:8888
spring.cloud.config.username=user
spring.cloud.config.password=configpassword123
management.endpoints.web.exposure.include=*
配置客户端控制器类
@RefreshScope
@RestController
public class ConfigController {
@Value("${applicationname}")
private String appName;
@Value("${username}")
private String username;
@Value("${password}")
private String password;
@Value("${instancename}")
private String environment;
@Value("${dbconnection}")
private String dbConnection;
@GetMapping("/user")
public String getUser() {
return "Application: "+ appName +" Instance: "+ environment + " User: " + username + " / " + password;
}
@GetMapping("/dbconn")
public String getDBConnection() {
return dbConnection;
}
}