Currently we have spring applications which are deployed on to Tomcat Servers.We are trying to update application.properties dynamically on the fly, without restarting our server/service. What are our options?
Do we need right any polling service which listens to event changes and update props file?
You can use the Spring Config project. As per the microservice architecture, you can define a different spring profile based on the environment and you will get the capability to reload application properties on the fly without restarting the application using Spring cloud bus events. The same setup can be useful in monolithic architecture as well.
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.
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.
I have a microservice developed using Spring Boot. The application is deployed in pivotal cloud foundry. I have set the logs levels in logback.xml which is part of the application. In order to change the log level , I have to update the logback.xml and rebuild / redeploy the app. Is there a better way to do this without having to redeploy the app? Is there a way to set log level as env variable in PCF?
I have not used logback so don't know much on it. But may be this thread can help - Set Logging Level in Spring Boot via Environment Variable
If you are using Spring Boot 1.5 or higher, and PCF 1.9 or higher you can change log levels from the Apps Manager without having to redeploy:
http://docs.pivotal.io/pivotalcf/1-9/console/using-actuators.html#manage-log-levels
Have you ever thought of externalizing your application configuration.... Pcf provides a service called config-server, which uses a git repo for maintaining your application configuration....
Using spring boot actuator, you can actually reload the updated configuration without actually doing redeploy/rebuild of your app.
This links should help you:
https://docs.pivotal.io/spring-cloud-services/1-5/common/config-server/index.html
https://spring.io/guides/gs/centralized-configuration/
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.
I have to make one application in multi tenant using spring framework and eclipse IDE. I have created environment for spring programming. But how to create setup for multi tenant in it.
And from where i have to start making multi tenant application using spring?
Thanks for reply in advance.
You should start by designing your application to support multiple client organizations. There is no built in support for this from Spring side.
I have also participated in such application using Spring's routing datasource. You can read more at:
http://blog.springsource.org/2007/01/23/dynamic-datasource-routing/
Dynamic DataSource Routing