Spring-boot(maven) actuator,devtools not working - maven

I'm a newbie to spring-boot. Trying to create a simple web application using spring-boot maven. Basic static page display using dependency spring-boot-starter-web worked fine. When I included spring-boot-devtools and spring-boot-starter-actuator in pom.xml it is giving build error Re-run Maven using the -X switch to enable full debug logging.
I tried including spring-webmvc dependency in pom file, still the result is same.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.test</groupId>
<artifactId>jspTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>jspTest</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin
</artifactId>
</plugin>
</plugins>
</build>
I downloaded this project from spring.io (SPRING INITIALIZR website). Build project is getting failed.

<scope>runtime</scope> of spring-boot-devtools suppose not to be runtime. In fact according to the doc -
Developer tools are automatically disabled when running a fully
packaged application. If your application is launched from java -jar
or if it is started from a special classloader, then it is considered
a “production application”. Flagging the dependency as optional in
Maven or using a customdevelopmentOnly configuration in Gradle (as
shown above) is a best practice that prevents devtools from being
transitively applied to other modules that use your project.
So, change the dependency as below -
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>

you can update your pom.xml and change the version number to any previous stable version.It worked for me.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>**xyz_previous_.RELEASE**</version>
<relativePath/> <!-- lookup parent from repository -->

Related

Can't find RemoteSpringApplication on Intellij for live reload on Docker

I'm currently trying to run a Docker SpringBoot Project with live reload using SpringBoot Devtools and following this documentation
I made the changes in my POM.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>br.com.myproject.teste</groupId>
<artifactId>hello</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>hello</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>build</scope>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludeDevtools>false</excludeDevtools>
</configuration>
</plugin>
</plugins>
</build>
</project>
And added the secret configuration on my application.properties
spring.devtools.remote.secret=${SPRING_REMOTE_SECRET:secret}
When I try to create de Intellij configurarion to use the RemoteSpringApplication as main class
it cannot find the class, in fact it does not find the org.springframework.boot.devtools whole package.
The application is running in Docker container created from this Dockerfile
FROM openjdk:11
WORKDIR /app
COPY target/hello-0.0.1-SNAPSHOT.jar /app/hello-ms-0.0.1-SNAPSHOT.jar
ENTRYPOINT ["java","-jar", "/app/hello-0.0.1-SNAPSHOT.jar"]
And except for the live reload functionality, it is working. Am I missing something?
Edit 1: There was a problem with the scope of the devtools plugin. (thanks #xerx593)
Edit 2: THe live reload and devtools seems to be working fine and if I run the application locally with mvn spring-boot:run, it reloads when changes are made in the project. The problem is running the project via SpringRemoteApplication that IntelliJ can't find so I can configure it as main class

Spring boot app not starting with embedded erver

APPLICATION FAILED TO START
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:183)
The following method did not exist:
org.apache.tomcat.util.modeler.Registry.disableRegistry()V
Maven clean install not working
Pom.Xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>boot.practice</groupId>
<artifactId>config</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>config</name>
<description>practice project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
I was finally able to resolve it . The problem was that the spring boot 2.5.0 was using tomcat 9.0.46 by default while my system had tomcat 9.0.0.M15 . So when I ran the application as "run on server" the tomcat 9.0.0.m15 added to my class path and then when ever I was doing run as java applicationit was throwing the error. Clearing the tomcat embedded repo from .M2 path and updating the local system with tomcat 9.0.46 fixed the problem

Why spring-boot-build parent dependency is missig?

I know that when I am inheriting from spring-boot-starter-parent I'll have this inheritance chain:
my-project => spring-boot-starter-parent => spring-boot-dependencies => spring-boot-build => maven parent pom
=>(means inherit)
Indeed That's what I saw in Github. And I believe It is true.
But when I am navigating through these POMs on my IDE (IntelliJ) the spring-boot-dependencies does not declare a parent pom (which should be spring-boot-build according to GitHub)
Why there is no inheritance specified in spring-boot-dependencies in my IDE(there is one GitHub)? I am missing something?
Edit
My project's pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
It doesn't show the parent POM relation in your IDE, because in the pom file for spring-boot-dependencies, that's deployed to the central Maven repository, there is no parent tag: https://search.maven.org/artifact/org.springframework.boot/spring-boot-dependencies/2.2.0.RELEASE/pom
Eclipse will load that pom file, not the one from the source repository.
So it looks that the build process from Spring Boot removes the parent tag, when it's deploying the pom to Maven Central.
A reason for this could be (and the naming suggests it), that spring-boot-build only provides configuration and dependencies related to the build process for Spring Boot itself, but isn't necessary or desired for applications using it.

What dependency is missing from this Spring Boot Application?

I would like to create a Spring boot Web application with H2 database and JPA support. But STS throws an error at pom.xml overview :
Missing artifact org.springrfamework.boot:spring-boot-test.jar:1.5.6.RELASE (Click for 49 more)
Here is my pom.xml , I have no idea what's the problem.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>data-demo-CS</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Actually your ide not getting the dependency, you should clean build again and if still showing error then simply remove that dependencies from your local repository (I. e. ./.m2 if using maven) and clean build your project again then all required dependencies will be downloaded I your local.
Command mvn clean compile package install

Spring boot executable jar unable to load jsp file?

I am new to Spring Boot application development. I refer here to develop my first Spring Boot application.
Here is my pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>SpringBoot</groupId>
<artifactId>spring-boot-web-jsp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>spring-boot-web-jsp</name>
<description>Spring Boot Web JSP Example</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<!-- JSTL for JSP -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!-- Need this to compile JSP -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
<version>4.6.1</version>
</dependency>
<!-- Optional, test for static content, bootstrap CSS-->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.7</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</build>
</project>
In Eclipse STS the project structure looks like following:-
Now if I run my application using IDE then everything works fine. Or if I build using apache-maven (mvn clean package) and run through cmd (java -jer target/spring-boot-web-jsp-0.0.1-SNAPSHOT.jar) also works fine. It ended with opening the following web page:-
But my understanding from here also says if I double click on the executable spring-boot-web-jsp-0.0.1-SNAPSHOT.jar should also open above web page.
Is my understanding wrong or I am doning something wrong?
As M.Deinum pointed out in comments, it's not possible to develop a web application whose view technology is JSP and build as an executable jar. In order to do so either, you have to change the view technology or change build type to war.

Resources