0

I've created a personal repository on Git where I have kept my application.properties file.

I've created a cloud config server ('my-config-server') and used the git repository url.

I have bound my spring-boot application that is supposed to access the external properties file with Git repository.

@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;
}

}

Another Class:

public class SDPropertiesUtil {

@Autowired
public Environment env;

public SDObj getObj(BigDecimal value) {

String valueStr = env.getProperty(value.toString());
/*do logic*/ 
}

My application starts but fails to load properties file from my git repository.

I believe I should have an application.properties at src/main/resources in my application but since I'm using

@PropertySource("application.properties") 
@ConfigurationProperties

I'm telling my application to use the application.properties from an external location and do not use internal properties file. But this is not happening. My application is still using the internal properties file.

Tiya
  • 553
  • 8
  • 26

1 Answers1

0

The source you included doesn't show your app configuration settings to connect to the Config server. Do you mind sharing it?

This is how the config server could be queried from a client app:

/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties

Let's say a Config server points to a Git repo which includes this file: demo-config-client-development.properties

You should be able to query the Config Server as:

curl http://localhost:8101/demo-config-client-development.properties

Assuming Config Server is running in locally and listening on 8181.

Let's also say you have a client app named: demo-config-client that connects to the Config server and runs using the development Spring profile, this app would now be able to read remote properties hosted in a Git repo through a Config server.

A detailed tutorial could be found at my blog at: http://tech.asimio.net/2016/12/09/Centralized-and-Versioned-Configuration-using-Spring-Cloud-Config-Server-and-Git.html

ootero
  • 3,235
  • 2
  • 16
  • 22
  • I created a config server using cf create-service command.... I provided my git repository url to the server and in my spring-boot application, I added the config server name ( services: - config-server)in order to bind the app with server once the app is push. – Tiya May 10 '17 at 16:48
  • Then try using a Spring profile, -Pspring.profiles.active=dev for instance and rename the properties file in Git to -dev.properties. @PropertySource("application.properties") is not needed – ootero May 10 '17 at 18:01
  • I removed @PropertySource("application.properties"), but how will my spring boot app understand which properties file from Git to refer and where exactly the file is located in Git? – Tiya May 10 '17 at 19:18
  • Could you paste your service config settings that should connect with the Config Server? Also, as I mentioned in the answer above, if your service is named blah, create a properties file in Git named blah-dev.properties, then run the blah service using the dev profile, something like java -Dspring.profiles.active=dev -jar target/blah.jar – ootero May 10 '17 at 19:56