Spring boot @ConfigurationProperties不拉取外部属性文件

Spring boot @ConfigurationProperties不拉取外部属性文件,spring-boot,cloud,configserver,Spring Boot,Cloud,Configserver,我在Git上创建了一个个人存储库,其中保存了application.properties文件 我已经创建了一个云配置服务器(“my-config-server”),并使用了git存储库url 我已经将本应访问外部属性文件的spring boot应用程序绑定到Git存储库 @javax.jws.WebService( serviceName = "myService", portName = "my_service",

我在Git上创建了一个个人存储库,其中保存了application.properties文件

我已经创建了一个云配置服务器(“my-config-server”),并使用了git存储库url

我已经将本应访问外部属性文件的spring boot应用程序绑定到Git存储库

@javax.jws.WebService(
                  serviceName = "myService",
                  portName = "my_service",
                  targetNamespace = "urn://vdc.com/xmlmessaging/SD",
                  wsdlLocation = "classpath:myService.wsdl",
                  endpointInterface = "com.my.service.SDType")

@PropertySource("application.properties") 
@ConfigurationProperties
public class SDTypeImpl implements SDType {

/*It has various services implementation that use following method**/

private SDObj getObj (BigDecimal value) {
    AnnotationConfigApplicationContext context =
                  new AnnotationConfigApplicationContext(
                          SDTypeImpl.class);
    SDObj obj = context.getBean(SDPropertiesUtil.class).getObj(value);
    context.close();
    return obj;
}
}

另一类:

public class SDPropertiesUtil {

@Autowired
public Environment env;

public SDObj getObj(BigDecimal value) {

String valueStr = env.getProperty(value.toString());
/*do logic*/ 
}
我的应用程序启动,但无法从git存储库加载属性文件

@javax.jws.WebService(
                  serviceName = "myService",
                  portName = "my_service",
                  targetNamespace = "urn://vdc.com/xmlmessaging/SD",
                  wsdlLocation = "classpath:myService.wsdl",
                  endpointInterface = "com.my.service.SDType")

@PropertySource("application.properties") 
@ConfigurationProperties
public class SDTypeImpl implements SDType {

/*It has various services implementation that use following method**/

private SDObj getObj (BigDecimal value) {
    AnnotationConfigApplicationContext context =
                  new AnnotationConfigApplicationContext(
                          SDTypeImpl.class);
    SDObj obj = context.getBean(SDPropertiesUtil.class).getObj(value);
    context.close();
    return obj;
}
我相信我的应用程序中应该在src/main/resources处有一个application.properties

@PropertySource("application.properties") 
@ConfigurationProperties

我告诉我的应用程序使用外部位置的application.properties,不要使用内部属性文件。但这并没有发生。我的应用程序仍在使用内部属性文件。

您包含的源文件未显示要连接到配置服务器的应用程序配置设置。你介意和我分享吗

这是如何从客户端应用程序查询配置服务器:

/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties
假设一个配置服务器指向一个Git repo,其中包含以下文件:demo-Config-client-development.properties

您应该能够通过以下方式查询配置服务器:

curl http://localhost:8101/demo-config-client-development.properties
假设配置服务器在本地运行并在8181上侦听

假设您有一个名为:demo-config-client的客户端应用程序,它连接到配置服务器并使用developmentSpring配置文件运行,该应用程序现在可以通过配置服务器读取Git repo中托管的远程属性


详细的教程可以在我的博客上找到:

@pranethramesh,你知道发生了什么吗?我使用cf create service命令创建了一个配置服务器。。。。我向服务器提供了我的git存储库url,并在我的spring boot应用程序中添加了配置服务器名称(services:-config server),以便在推送应用程序后将应用程序与服务器绑定。然后尝试使用spring配置文件,-Pspring.profiles.active=dev,并将git中的属性文件重命名为-dev.properties@不需要PropertySource(“application.properties”)我删除了@PropertySource(“application.properties”),但是我的spring boot应用程序如何理解要引用的Git中的哪个属性文件以及该文件在Git中的确切位置?你能粘贴应该连接到配置服务器的服务配置设置吗?另外,正如我在上面的回答中提到的,如果您的服务名为blah,那么在Git中创建一个名为blah-dev.properties的属性文件,然后使用dev概要文件运行blah服务,类似于java-Dspring.profiles.active=dev-jar target/blah.jar