Deploy Spring boot application in Scaleway Kubernetes - spring-boot

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

Related

Failed to execute goal... error. Deploying to Heroku

I am trying to deploy my application to Heroku, but I'm geting this message all the time. When I run it in IntelliJ the application is working.
The application is written in Spring Boot.
What could be the cause of this error?
Here is my pom.xml
I think the problem is due to a mismatch of the Java version in your project's pom.xml file and that being used by Heroku.
A simple solution could be either specify your target version in pom.xml or configure the Java version in Heroku. You can add the following code below <description> in your pom.xml file to specify your target version.
<properties>
<java.version>1.8</java.version>
</properties>

Spring Boot - Could not resolve placeholder when ran from jar file

I'm running into this strange issue where I can run my Spring Boot application without problems from within Intellij, but when I do:
mvn clean package -Pst -Dspring.profiles.active=st && java -jar target/myapp-0.0.1-SNAPSHOT.jar
I can see errors saying Spring Boot cannot resolve the #Value placeholders.
ERROR o.s.boot.SpringApplication - Application startup failed
java.lang.IllegalArgumentException: Could not resolve placeholder
What I did to investigate was to get the jar file and extract the files like using jar xf myapp.jar and I can see the properties files in the classpath root. Initially I had this problem that Maven was not packaging my properties and statics from the main/resource folder, but I already resolved that with:
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>static</directory>
<targetPath>static</targetPath>
</resource>
Any comments, ideas what could I be missing here?
I managed to resolve this. It was really weird, it seems that I need to tell java in which profile to run the jar in e.g --spring.profiles.active=st.
mvn clean package -Pst -Dspring.profiles.active=st && java -jar target/myapp-0.0.1-SNAPSHOT.jar --spring.profiles.active=st
It is not Maven deciding, what Spring Profile you use, but the Spring container during every single execution of the jar. The differen profiles are all available. The Spring profile is used to adapt the executable to different environments by configuration.
There are additionally Maven profiles, but they configure the build of the executable, not the execution.

info endpoint - application.yml maven filtering not working

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>

Versioning issue when using jersey 2.9 with tomcat7 + java8

We have a maven project to develop a jersey 2.0 REST service, on Eclipse (kepler)
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.9.1</version>
</dependency>
In conjunction with:
java8
tomcat7
When deploying the web application (using $ mvn install && mvn -X tomcat7:redeploy) we get the below exception:
Caused by: java.lang.UnsupportedClassVersionError: org/glassfish/jersey/servlet/init/JerseyServletContainerInitializer : Unsupported major.minor version 51.0 (unable to load class org.glassfish.jersey.servlet.init.JerseyServletContainerInitializer)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2840)
I examined the MANIFEST file in the org.glassfish.jersey.containers jar, and (as suspected) it says build on 1.7 JDK
Tomcat logs confirm that it uses java8 itself
We cannot move back to java8. Is there a way/hack we can get past this error?
From tomcat 7.0.26, I upgraded to next version > Tomcat 7.0.47, to see if that helps.
Things started working magically. Deployed app successfully
Would be glad if someone can explain how the same plugin started to ignore jdk versions, just due to a change in tomcat version.

How can I configure the heap size when starting a Spring Boot application with embedded Tomcat?

I am trying to deploy a Spring Boot powered web app to production. The app is built with Spring Boot 1.0.1 and has the default Tomcat 7 embedded as application server. I want to allocate larger memory to the app when start the app with java -jar myapp.jar command line.
Should I use JVM parameter such as -Xms -Xmx or use environment variable such as JAVA_OPTS? I have tried to look for the answer in documentation or google it, but I did not get an answer. Can anyone give some hints?
If starting the application with the spring-boot plugin:
mvn spring-boot:run -Drun.jvmArguments="-Xmx512m" -Drun.profiles=dev
Otherwise if running java -jar:
java -Xmx512m -Dspring.profiles.active=dev -jar app.jar
Since this is specifically a Spring Boot question, I'd argue that a more useful answer than #DaveSyer's is this:
You can drop a .conf file in the same directory as your WAR file that is effectively a shell script.
For example,
$ ls
myapp.conf
myapp.war
$ cat myapp.conf
export JAVA_OPTS="-Xmx1024m -Xms256m"
Any configuration you do there will be run before the Spring Boot embedded Tomcat starts up. Personally, I version control a .conf.example file in my application itself and then drop a copy of it on each server I deploy to.
Of course, anything you set in that .conf file is overridable with command-line operations.
Just use whatever normal mechanism you would to set up the JVM. Documentation is available on the command line:
$ java -X
...
-Xms<size> Set initial Java heap size
-Xmx<size> Set maximum Java heap size
...
For Spring Boot 2, you have to specify the heap size in the pom.xml file as below:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<jvmArguments>-Xmx64m</jvmArguments>
</configuration>
</plugin>
For Spring Boot 1, the Maven argument to specify in the plugin configuration is jvmArguments, and the user property is run.jvmArguments:
mvn spring-boot:run -Drun.jvmArguments="-Xms2048m -Xmx4096m"
For Spring Boot 2, the Maven argument to specify in the plugin configuration is also jvmArguments, but the user property is now spring-boot.run.jvmArguments:
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Xms2048m -Xmx4096m"
So if you use the plugin configuration way, both for Spring Boot 1 and 2 you can do that:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<jvmArguments>
-Xms4048m
-Xmx8096m
</jvmArguments>
</configuration>
</plugin>

Resources