Spring cloud override config in local (spring boot 2.4 upper) - spring

In previous Spring Cloud Config Hoxton by set spring.cloud.config.allow-override=true, you can override config in localhost application.yaml.
But in the new Spring Boot 2.4 version and spring.config.import command, setting this property does not change anything, and config does not override in localhost application.yaml.
How can I do this in the new version? Is there any alternative solution for override configs to test in the local environment?

I just added a new e.g. application-dev1.yml in addition to other yml files (in this case besides test) and I set the active profiles in application.yml as below
spring:
profiles:
active: test, dev1
It works for me

Related

How do I override configuration in application.yml in spring boot (2.4.2) generated docker image?

I used spring boot 2.4.2
Generated docker image using the command mvn spring-boot:build-image -Dspring-boot.build-image.imageName=XXXXXX.azurecr.io/fake-XXXXX:0215
I have hostnames in application.yml that I need to override
So I passed -Dspring.data.mongodb.host=mongo_db in docker-compose under command: BUT it is not overriding. .. Below screenshot for reference.
I understand that Buildpacks are used to build the layered jar.
If this was docker image created by me manually and not by spring boot then I would have ENTRYPOINT in Dockerfile and command in docker-compose where I would have given command: Dspring.data.mongodb.host=mongo_db -jar fake-XXXX.jar
I know #6 works but would like to use the latest and greatest spring boot in my new project. Hence kindly let me know your thoughts.
Why don't you try the approach via Spring Config or Harshi Corp Consul KV feature and read your config from there. Check-in your config to a repo and have config framework read it from there and pass it to your app? You can change the config at runtime (probably requires restart of containers to reload the modified KV fields in some case)

Manage build profiles/configs for Spring Boot application

I have written application using spring boot + scala with sbt and now I need to divide build configurations for dev and prod.
What has been done: created configs application.yml and application(-dev/prod).yml to start application locally, on dev and prod respectively.
What need to be done: find a way to configure spring boot profile (dev, prod) in javaopts or directly write corresponding config, also in javaopts.
I've tried to use these opts:
sbt service/run -Dspring.profiles.active=...
sbt service/run -Dspring.config.location=...
The answer is to configure active profile like this:
sbt service/run --spring.profiles.active=...

Spring boot devtools does not consider exclude property

I am using Spring Boot with Gradle and added the Devtools plugin. My application is creating files in src/main/resources so I don't want it to be restarted when this is changed. I have tried the following settings in application config file:
spring.devtools.restart.exclude= src/main/resources
spring.devtools.restart.exclude= resources
spring.devtools.restart.exclude= resources/**
spring.devtools.restart.exclude= src/main/resources/**
but none worked.
How can I configure spring boot devtools to ignore files changed in resources folder?

how to deploy Spring Cloud war to old container

I had a Spring Cloud project which was deployed in embeded tomcat. Now I modify the project add web.xml and make the Application class extends SpringBootServletInitializer. I followed the instruction of 81.5 Deploying a WAR in an Old (Servlet 2.5) Container in below link. But I found that the application.properties was not loaded. And the server port listed in application.properties was not listened.
[http://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html#howto-servlet-2-5]
Deploying a WAR in an Old (Servlet 2.5) Container
application.properties
spring.application.name=api-gateway
server.port=5555
# routes to serviceId
zuul.routes.api-a.path=/api-a/**
zuul.routes.api-a.serviceId=service-A
zuul.routes.api-b.path=/api-b/**
zuul.routes.api-b.serviceId=service-B
# routes to url
zuul.routes.api-a-url.path=/api-a-url/**
zuul.routes.api-a-url.url=http://localhost:2222/
eureka.client.serviceUrl.defaultZone=http://localhost:9999/eureka/

Spring Boot and Jboss wildfly setting the context root

I am trying to set the context root of my spring boot application. I'm deploying my application as a war file to Jboss.
i've tried to set the contextPath of what I'd like my root URL to be when deploying it to JBoss/Wildfly but it seems to get ignored. Unless I add a jboss-web.xml file setting a contex-root variable, my deployment url is always based on the war file name:
e.g. : myapp.war always deploys as : localhost:8080/myapp unless I use jboss-web. I've tried setting the contextPath in the server.properties file and it doesn't seem to work.
My question is should I be able to? I'm using the latest Spring Boot.
In other words, add your jboss-web.xml
file in this directory : /src/main/webapp/WEB-INF
Content of your jboss-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<context-root>/</context-root>
</jboss-web>
All of the server.* properties that Spring Boot supports only apply to the configuration of the embedded servlet container (Tomcat, Jetty, or Undertow). If you're deploying your Spring Boot app to a standalone server then you'll need to configure that server using whatever mechanisms it provides.

Resources