Maven Build Fails when "spring-boot-starter-web-services" starter is used with 2.1.13.RELEASE of Spring Boot Version - spring

I am not able to build spring boot application when spring web service starter is used with 2.1.13.RELEASE version of spring boot. This is coming due to spring-ws-core:jar:3.0.8.RELEASE.
Exception while building application : It comes during default test case execution .
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.ws.config.annotation.WsConfigurationSupport] from ClassLoader [sun.misc.Launcher$AppClassLoader#42a57993]
Caused by: java.lang.NoClassDefFoundError: org/springframework/xml/transform/TransformerObjectSupport
Caused by: java.lang.ClassNotFoundException: org.springframework.xml.transform.TransformerObjectSupport
Warning :
The POM for org.springframework.ws:spring-ws-core:jar:3.0.8.RELEASE is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
Pom File :
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.13.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-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</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>
</project>

Although there are many ways to solve the issue, the best option is :-
Use a newer version of spring-boot-starter-parent
e.g.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.3.RELEASE</version>
</parent>
issue solved.

Related

spring boot Maven project import error in sts

I am facing error while importing spring boot maven project in sts-4.6.0.RELEASE :
An internal error occurred during: "Importing Maven projects".
org/springframework/tooling/boot/ls/xml/XMLRootElementContentDescriber2$QualifiedElement
Java version installed in my laptop is 1.8.0_241 and maven version is 3.6.3 below is the image attached of the error which i am facing while importing spring boot project..
Below is 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.2.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.developer.app.ws</groupId>
<artifactId>mobile-app-ws</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>mobile-app-ws</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-web</artifactId>
</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>
</project>

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.

Spring-boot(maven) actuator,devtools not working

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 -->

ClassNotFoundException using Spring Boot and Spring Cloud

I am trying to use feature from Spring Cloud (ex: Feign or Zipkin Client) in a Spring Boot micro-service. Whenever I introduce the Spring Cloud dependencies into the pom.xml I get the following error at startup:
java.lang.ClassNotFoundException: com.fasterxml.jackson.core.Versioned
at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.8.0_162]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_162]
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) ~[na:1.8.0_162]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_162]
... 36 common frames omitted
Below is a sample pom.xml causing this. I am currently on Spring Boot 2.0.0.RELEASE and Spring Cloud Finchley.M8.
What am I doing wrong? Should I switch to another version of Spring Cloud?
UPDATE: It's not me who's doing it wrong, even Spring Initializr projects demonstrate this issue. To repro:
Go to https://start.spring.io/.
Enter Web, JPA and Feign as dependencies
Download the project.
Launch in IDE (in my case Spring Tool Suite) and the exception will be thrown at startup.
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>io.urig</groupId>
<artifactId>inventory</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>inventory</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.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>
<spring-cloud.version>Finchley.M8</spring-cloud.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.retry</groupId>
<artifactId>spring-retry</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Turns out the issue was a corrupt Maven package. Deleting my .m2\repository folder and running mvn spring-boot:run to downloaded dependencies and run my app resolved the issue.

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

Resources