我正在从这里学习 Spring Boot v.2.3.9.RELEASE + 微服务项目 - https://www.youtube.com/watch?v=Z7A_M8HkJG0
在此示例中,我无法使用 spring-cloud-config 从属性文件中获取详细信息。
弹簧配置服务器
应用程序.yml
spring:
application:
name: config-server
cloud:
config:
server:
git:
uri: https://github.com/techefx/environment-variable-repo.git
server:
port: ${port:8888}
配置服务器应用程序.java
@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
属性访问服务
属性访问Bean.java
@Component
@ConfigurationProperties(prefix = "property-file")
@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PropertyAccessBean {
private String name;
private String description;
}
属性访问值.java
@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PropertyAccessValue {
private String name;
private String description;
}
PropertyAccessServiceApplication.java
@SpringBootApplication
public class PropertyAccessServiceApplication {
public static void main(String[] args) {
SpringApplication.run(PropertyAccessServiceApplication.class, args);
}
}