info endpoint - application.yml maven filtering not working - spring-boot

We are using spring boot 1.3.1.
I have following details in my application.yml file.
info:
build:
artifact: ${project.artifactId}
name: ${project.name}
description: ${project.description}
version: ${project.version}
I am building the war file and deploying it to tomcat. When I access /info endpoint, i don't see values are substituted.
I am not using 'spring-boot-maven-plugin' as i don't need to run the application standalone.
Does the filtering work for YML files by default?
Also, is there any example of showing application version on banner.txt file using maven project.version property?
After Dave's comment, I updated my application.yml file as shown below and it is working.
info:
build:
artifact: #project.artifactId#
name: #project.name#
description: #project.description#
version: #project.version#
Also, I found that application.version is not picked up in standalone tomcat for banner.txt file. Tomcat fails to read manifest.mf file.
Spring boot issue: https://github.com/spring-projects/spring-boot/issues/3406

I don't think filtering is switched on in maven by default. If you use the spring-boot-starter-parent it is enabled, but the key for the placeholders is #..# not ${..}.

I don't know which version of spring boot you are using,
But for me version: #project.version# did not work.
Instead version: #project.version# worked for me.
My project is having following parent pom config :
<parent>
<artifactId>spring-boot-starter-parent</artifactId>
<groupId>org.springframework.boot</groupId>
<version>1.4.1.RELEASE</version>
<relativePath />
</parent>

Related

Deploy Spring boot application in Scaleway Kubernetes

I'm trying to deploy a spring boot application in Kubernetes hosted by Scaleway.
After the deployment, I have the following error :
java.lang.UnsupportedClassVersionError: xx/yy/zz/Application has been compiled by a more recent version of the Java Runtime (class file version 62.0), this version of the Java Runtime only recognizes class file versions up to 58.0
My pom file has the following properties :
<properties>
<java.version>18</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
In my dockerfile configuration, I use the following config :
FROM --platform=linux/amd64 openjdk:14-jdk-alpine
RUN addgroup -S spring && adduser -S spring -G spring
USER spring:spring
I tried different versions without solving the problem.
Do you have an idea ?
You are compiling your application for a newer JVM than the container image, that is executing the application, provides.
You are also mixing the compiler settings with the old (maven.compiler) and newer (java.version) syntax.
Leaving out the "java.version" setting should fix your immediate issue.
The kubernetes configuration lacks the imagePullPolicy: Always property

Spring cloud config client is not getting/loading configuration files from config server after upgrading to 2.4.0

spring-cloud-config-client is not able to read configuration files from the spring-cloud-config-server after upgrading to 2.4.0 with spring-cloud version 2020.0.0-M6
From spring-boot 2.4.0 version, bootstrapping is not enabled by default, need to add the following dependency in your build.gradle
implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap'
or pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
Adding to the application file (.properties or .yml) the property spring.config.import , with this it is not necessary to change/add the project's dependencies
Example:
To connect with the default location of "http://localhost:8888" or de value defined in the property spring.cloud.config.uri
spring.config.import=optional:configserver:
For more info:
https://docs.spring.io/spring-cloud-config/docs/3.0.0/reference/html/#config-data-import
For new spring cloud versions please don't use the legacy dependency spring-cloud-starter-bootstrap instead you need to use application.yml/application.properties instead of bootstrap.yml/bootstrap.properties and then set into that file the following properties:
spring:
config:
import: configserver:${your_config_server_url} # example: import: configserver:http://192.168.0.4:8080
cloud:
config:
username: ${your_config_server_auth_user} # This is required only if your config server use authentication
password: ${your_config_server_auth_password} # This is required only if your config server use authentication

Add VERSION_INFO to jar

How to add VERSION_INFO meta data to jar with spring boot ?
I have seen the plugin
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
with the execution "repackage" but I cannot add this meta_data in my executable jar file.
Do you really need the version in META-INF/MANIFEST.MF?
If you add these placeholders to application.yml properties file:
# app name and build version updated during build process from Maven properties.
info:
app:
name: #project.artifactId#
build:
version: #project.version#
They get replaced while building the artifact and available when sending a GET request to /info actuator endpoint, for instance:
curl "http://localhost:8080/info"
{"app":{"name":"demo-cxf"},"build":{"version":"0-SNAPSHOT"}}

Maven control version of transitive dependencies of Spring Boot

I have a simple spring boot app that I am trying to add spring cloud consul to. Spring cloud consul relies on a newer version of spring boot. In my POM I have specified version 1.3.5.RELEASE for all my spring boot artifacts.
The problem is that, even though version 1.3.5 is specified for spring-boot-starter-web it still downloads dependencies with version 1.2.3
Is there a way to have maven get the 1.3.5.RELEASE for ALL spring boot artifacts, including transitive dependencies? I know I can explicitly list them all, but is there a better way?
Here is the POM depenency view from eclipse:
Yes, simple use correct parent:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.6.RELEASE</version>
<relativePath/>
</parent>
and remove versions from spring boot dependencies.

How is a war file created for spring boot with maven?

I'm trying to follow the guide for converting a spring project to a war.
http://spring.io/guides/gs/convert-jar-to-war/
It starts out using maven and gradle and then right after the jar portion it completely forgets about maven and only has gradle updates.
There are two main changes that you need to make in the pom. The first is to change the project's packaging type to war:
<groupId>org.springframework</groupId>
<artifactId>gs-convert-jar-to-war</artifactId>
<version>0.1.0</version>
<packaging>war</packaging>
The second is to add a dependency on spring-boot-starter-tomcat and mark it as provided:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
mvn package will now produce a war file that can be run using java -jar or deployed to a separate servlet container.
There is an official guide at spring:
http://spring.io/guides/gs/convert-jar-to-war-maven/
Pay attention to "Initialize the servlet" section.
It explains an important point of adding a class that substitutes web.xml. Without it (or without proper web.xml) you will get a war file but when deployed nothing will be accessible in browser as nothing will be registered as your request dispatcher.
Also note that it is best to run this example on Tomcat 8 as it supports latest servlet specs. I have spent number of hours trying to figure out why it does not work on my Tomcat 7.

Resources