Spring Boot external configuration on another server - java

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.

Related

Spring Cloud Config Server With Non-Spring Application

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

How to Modify application.properties file dynamically in spring application?

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.

How can I Host my files present in resources through Spring Boot App

I have a requirement in which I have to store some files within the Spring Boot Application and on API hit I should provide a URL for each file present within the Spring Application.
Any advice on how can I achieve it, without any Storage Service like S3.
Java Files and the hosting files should be within the same project and same server.
Thanks in advance.

How to deploy spring boot web application with configurable properties

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.

Spring Integration + Spring Boot Actuator Endpoints not showing up

I have been trying to learn more about Spring Boot and I would like to add the Actuator endpoints to my test Spring integration/Spring Boot project. However, it is a plain, CLI Spring integration project--there are no current REST or web services. I'd ideally like to add the ability to view the endpoints with a browser while the jar is running from the command line.
I have been looking through the tutorials and I'm not finding a lot on adding it to a regular project, rather than a web project.
I've added the dependencies (spring-boot-actuator), and can see the endpoints from the jconsole, but I never see a connection to a port on my system (using netstat) and never can navigate there.
Is there a tutorial or something that can show me how to have REST endpoints with a CLI project?
Thank you
newbo
You can monitor and manage your application using JMX instead. See the documentation here.
If you use IntelliJ IDEA, hit CTRL+Space in an application.properties file to see a lot of JMX properties ready for you, one of them being:
endpoints.jmx.enabled=true (true is the default value)
According to Spring Docs, in order to show the endpoint user need to have ACTUATOR role.If you need to access without having the role you need to add the following value to application.properties:
management.security.enabled=false
I think if it isn't a web project, no tomcat servlet will be embedded, therefor you wont be able to browse the actuator endpoints over http
Insert dependency spring-boot-starter-web into your project and it will probably work.

Categories