So I have a Servlet/JSP web application. We used Ant scripts to build scripts to build properties for different environments, during deployment using loads of filtering. But we are now moving the application to build with Maven. We are thinking of using Spring Cloud Config as centralized repository for property files for all environments that we have. So primarily my question was:
Can we use Spring Cloud Config Server to host properties and fetch it in a non-Spring application?
Can we use Spring Cloud Config to fetch XML, XSD, Text files too? (This is a bit of stretch but just asking if its possible)
We don't plan to use GIT as repository for property, just use a filesystem.
Any pointers would be appreciated.
Spring Cloud Config Server provides an HTTP API that is described in the "Quick Start" section of the Spring Cloud Config documentation. You can use GET requests to fetch configuration properties for specific applications and profiles, e.g.:
curl http://config-server-host:8888/my-application/dev
Using the HTTP API allows you to integrate Config Server with applications that are not based on Spring.
Spring Cloud Config Server can also return non-property files that are handled as "plain text". Please review section "Serving Plain Text" in the Spring Cloud Config documentation:
The Config Server provides these through an additional endpoint at /{application}/{profile}/{label}/{path}, where application, profile, and label have the same meaning as the regular environment endpoint, but path is a path to a file name (such as log.xml).
A curl request for a logback.xml file would therefore look as follows:
curl http://config-server-host:8888/my-application/dev/logback.xml?useDefaultLabel
Related
I am deploying plain Java application and spring application(without spring boot) into kubernetes.
I have planned to mount config map into a volume and refer it as part of deployment yaml file.
Query:
If I update the config map, I want the application to reload the properties .
I have seen some references where this can be done with spring cloud and it provides access to kubernetes as well.
I want to know if by any way the same can be done for normal Java application and a Spring application.
i am using terraform scripts to create AWS resources. Using AWS ElastiCached memcached for caching some data.
output "configuration_endpoint" {
value = "${aws_elasticache_cluster.memcache.configuration_endpoint}"
}
i want to dynamically configure the memcached configuration end point into the spring boot application.properties file instead of hard coding it.
Currently its as below
memcached.addresses=xyz.cache.amazonaws.com:11211
i am unable to find any good references online for the same. Is there any way to set this dynamically once the resources are created in aws. I use Jenkins to run this terraform script and deploy the springboot application into AWS.
We have a suite of microservices that are currently hosted on AWS ECS-Fargate. They are implemented using Spring Boot and packaged as a Docker container using an OpenJDK-based image.
Application logging is configured using logging.config from the Spring runtime core properties and currently points to a bundled classpath resource as follows:
logging:
config: 'classpath:config/logback-spring.xml'
At the ECS task level we configure logs using the awslogs driver which redirects all console output to AWS CloudWatch.
However, this approach is quickly proving unwieldy as it requires us to rebuild and subsequently redeploy the microservices everytime we need to modify the logging configuration.
What is the current best practice for configuring logs using resources external to the application when hosted within the AWS environment?
After researching i learned that the common way to deploy spring boot web applications is as a war file.However,i have a project i made for a company,now i need to send them the project to try it out and they need to be able to configure the application.properties or to be specific the database location and credentials.so my question is do i need to deploy the project in a different way or is there a way to make the war file application properties modifiable later ?
Did you consider Spring Cloud Config Server
https://cloud.spring.io/spring-cloud-config/multi/multi__spring_cloud_config_server.html.
This is the most elegant way to configure and externalize your properties. If not I would strongly suggest incorporating that component. Plug the config server with your spring boot app without much coding and your application will be much more manageable and extensible.
Spring Boot applications are actually typically packaged as Uber jars with Tomcat embedded. You can accomplish this using spring-boot maven plugin or a similar gradle plugin if need be.
Once in this state the jar can be started normally and you can override configuration properties when invoking it.
java $JAVA_OPTS -Dspring.service.name=my-service -jar /my-service.jar
EDIT: This is not the only way you can solve this problem, and #piy26's answer is an excellent solution for injecting external configuration into an enterprise ready spring boot application. However for the case that your are describing you would need the company to set up there own configuration server, and whats more they will still have to override the configuration server location property so the application will pull properties from their config-server. For your example it seems you need the simplest way to override application properties within the jar.
We are migrating applications to spring boot and we came to conclusion that it would be good to shift all configuration file to external server. I wonder if spring boot is capable of reading configuration file from another server during startup? If this is possible how can I achieve it? Now I read all config data from app-config.yml but in future I would like to get ride of this file from war. Thanks for any answers.
Of course spring has such stuff in the toolbox:
http://cloud.spring.io/spring-cloud-config/
This would give you a central configuration server backed e.g. by a git repository holding the configuration.
Hope this is what you are looking for.
You can user Spring Cloud Config Server, it allows to share a properties folder via rest services.
In your application client include Spring Cloud Config Client dependency to property sources read those values from server.