Error creating bean with name 'compositeCompatibilityVerifier' - spring-boot

I am using Spring Boot 2.5.5 with Spring Cloud Version 2020.0.4 but when I am trying to run the application I am getting below exception -
Exception encountered during context initialization - cancelling refresh attempt:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'compositeCompatibilityVerifier' defined in class path resource [org/springframework
/cloud/configuration/CompatibilityVerifierAutoConfiguration.class]: Bean instantiation
via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to instantiate
[org.springframework.cloud.configuration.CompositeCompatibilityVerifier]: Factory
method 'compositeCompatibilityVerifier' threw exception; nested exception is
org.springframework.cloud.configuration.CompatibilityNotMetException
pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>2020.0.4</spring-cloud.version>
</properties>
<dependencies>
<!-- Below jar file also has same Spring Boot Version -->
<dependency>
<groupId>com.another.project</groupId>
<artifactId>commons</artifactId>
<version>1</version>
<scope>compile</scope>
</dependency>
<!-- other spring boot 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>
I have another project jar included in pom which also has same Spring Boot Version that I doubt cause the issue but not sure how?

Your pom looks good. The only thing I would suggest is to check the spring components compatibility. The spring.io page you have a compatibility matrix, and you should double-check is the version you are trying to use compatible with spring boot.
Second thing you may try, is to not have a parent POM at all, but import spring boot, and spring cloud dependencies from their pom-s.
You added spring cloud, for spring boot do:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<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>

I had the same issue , when i used spring-cloud.version : 2020.0.3 and resolved it by using the version
<spring-cloud.version>2021.0.3</spring-cloud.version>

Check out the compatibility of the spring-cloud you are using with your spring-boot version: Spring-Cloud

Related

How to resolve 'Failed to load driver class com.mysql.cj.jdbc.Driver' with HikariDataSource?

I am getting the below exception while running Spring Boot application from Eclipse.
Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Unsatisfied dependency expressed through method 'dataSourceScriptDatabaseInitializer' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.RuntimeException: Failed to load driver class com.mysql.cj.jdbc.Driver in either of HikariConfig class loader or Thread context classloader
Spring Boot : 2.5.3
Java: 1.8
pom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.3</version>
<relativePath/>
</parent>
<groupId>spring-examples</groupId>
<artifactId>hplusapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>hplusapp</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-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</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>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
application.properties
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://localhost:3306/hplus
spring.datasource.username=root
spring.datasource.password=root
I have noticed if I remove the JPA dependency, I am not getting any error. But, I need JPA for further use cases. Can anyone guide me on this?
You are using MySQL but use a driver for MSSQL (Microsoft).
Remove
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<scope>runtime</scope>
</dependency>
and add
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>

Spring Boot 2 fails starting due to Hystrix?

I started investigating to migrate a Spring Boot application from 1.5.x to 2.
This appliication has a dependency to hystrix, which does not be compatible to Spring Boot 2 yet.
When I have the following in my pom:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
<version>1.4.4.RELEASE</version>
</dependency>
I get the following error when starting the application:
java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.<init>([Ljava/lang/Object;)V
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:125)
Anybody has experienced the same?
Is there a solution yet?
I have faced similar issue while integrating hystrix for my spring boot microservice that uses spring boot 2.0.x.
Instead of
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
<version>${spring-hystrix.version}</version>
</dependency>
I have moved to
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>${spring-hystrix.version}</version>
</dependency>
Spring boot 2.0.x application starts fine with the spring-cloud-starter-netflix-hystrix dependency without this issue.
For SpringBoot 2.0 version artifactID has been changed. Old dependency is
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
<version>${spring-hystrix.version}</version>
</dependency>
Use this new updated dependency with latest version
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>2.2.8.RELEASE</version>
</dependency>
for recent release version you can check MVNrepository
After a bit further research I found a solution by adding the following to the pom file:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.RC1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
all versions of spring-cloud-dependenciesseem to be incompatible to Spring Boot 2.x.x
I had this problem starting Spring Boot 2 as well because spring-cloud-starter-hystrix was a dependency I used in my project. However I found that spring-cloud-starter-hystrix has been deprecated. I also found the feign classes I was using in there have been moved to spring-cloud-openfeign (https://github.com/spring-cloud/spring-cloud-openfeign). So all I did was remove spring-cloud-starter-hystrix from my dependency and added spring-cloud-openfeign instead. This works perfectly for me.
Basically I replaced
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-hystrix', version: '1.4.4.RELEASE'
with
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-openfeign', version: '2.0.0.RELEASE'
and Spring Boot 2 is ready to go. Hope this helps.
NB: I use Gradle, you can easily find the maven pom dependency equivalents if necessary.
I faced a similar problem with Spring Boot 2, concisely 2.2.0.RELEASE. My mvn project compiled well but Spring Boot application stopped starting, without showing any real hints.
The solution that worked was using the artifact spring-cloud-starter-netflix-hystrix instead of spring-cloud-starter-hystrix from the same group. Then you can use the same same version as Spring Boot to retrieve the dependency.
From old pom.xml :
<!-- hysterix -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
<version>1.4.7.RELEASE</version>
</dependency>
New part in working pom.xml:
<!-- hysterix -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>${spring.boot.version}</version>
</dependency>
After some time spent on researching and testing, here is what I found and noticed
I think that in the latest Spring Boot version (2.5.x), the Hystrix looks to be deprecated or I just couldn't find out way to add it as a dependency.
So I downgraded the Spring boot version to 2.3.x where I managed to run the application
So here is how my working pom.xml looks like:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.12.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>org.hldservices</groupId>
<artifactId>payment-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>SpringCloudPaymentCircuitBreakerApplication</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
<spring-cloud.version>Hoxton.SR11</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</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-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</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>
Keep in mind that I had to add following configuration in my Project:
SpringCloudPaymentCircuitBreakerApplication(main class)
#EnableHystrix
#EnableHystrixDashboard
application.propreties
management.endpoints.web.exposure.include=*
hystrix.dashboard.proxyStreamAllowList=*

Spring Boot App module with custom parent - getting it to work

The goal: getting the Spring Boot app module which works perfectly with the spring-boot-starter-parent, to work with our own custom parent pom.
I am following this guide and am sorry to say I cannot get this to fully work.
https://www.surasint.com/spring-boot-with-no-parent-example/.
Concretely, with having the spring-boot-starter as parent pom everything works fine.
With our own parent pom, the Spring Boot app breaks.
I have a project setup with three modules and my own parent pom. This is needed for many reasons (the parent pom uses Maven profiles and sets important database variables depending on these profiles).
Parent pom (our custom).
Common – simple jar library.
Web – Spring Boot app with REST services and pure Java helpers (NOT any jsp or html). This used to inherit from spring-boot-starter parent – and now must inherit from our custom parent pom.
Worker – simple jar library with a worker thread.
I am using Spring Boot 1.5.9, Maven 3.3 and Java 8.
In theory I totally agree that it should work without having the spring-boot-starter-parent. However when making the Spring Boot module inheriting only from our parent pom and NOT from the spring-boot-starter-parent, the following (to me very weird) exceptions occur.
2018-02-07 16:06:46.822 ERROR 10008 --- [ main]
o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter]: Factory method 'requestMappingHandlerAdapter' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcValidator' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.validation.Validator]: Factory method 'mvcValidator' threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration.getApplicationContext()Lorg/springframework/context/ApplicationContext;
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
The project is fully green in IntelliJ and compile is OK. It is only when starting the Spring Boot app that these errors occurs. As I interpret it the Spring boot app module is now lacking something which it had before. Any advice here would be most helpful!
Concretely, what do you need to import (in Maven dependency-tags) for the module to have access to exactly the same thing – and everything – that it had when it was inheriting from the spring-boot-starter-parent instead of your own custom parent? It would be super that instead of by pure intuition guessing your dependencies (which apparently fails in my situation) there is a reference dependency checklist that makes sure your module have access to exactly the same thing as if inheriting from the spring-boot-starter-parent directly.
So far I've by pure intuition added the following to the Spring boot module (called "web" above)
<!-- === [Spring Boot Starter] === -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</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-web</artifactId>
</dependency>
Evidently something is missing which was present with the spring-boot-starter as parent. Moreover - and oddly enough - the rest of the possible spring-boot-starter dependencies seem totally irrelevant for the project (things like cloud-connectors, twitter-connectors, mongodb and related). I added all remotely relevant just to test but the errors below are still there. Any advice or help is most appreciated.
As a reference here is the parent pom:
<?xml version="1.0" encoding="UTF-8"?>
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
no.statnett.fasit
fasit-hub-backend
1.0-SNAPSHOT
common
worker
web
pom
Fasit Hub Backend
<!-- parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.source.encoding>UTF-8</project.source.encoding>
<project.source.version>1.8</project.source.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<spring.boot.version>1.5.9.RELEASE</spring.boot.version>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
<dependencyManagement>
<dependencies>
<!--
Import dependency management from Spring Boot
* This fixes the Spring boot parent issue [inherit dependencyManagement without forcing Spring Boot App]
* It does NOT include the plugin management
See https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-build-systems.html#using-boot-maven-without-a-parent
See http://www.logicbig.com/tutorials/spring-framework/spring-boot/starter-import/
-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring.boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring.boot.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa -->
<!-- === [Spring Boot JPA] ===-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.196</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.1</version>
</dependency>
<!-- === [Spring Boot Security] ===-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<!-- === [Spring Boot Maven plugin needed for profile management] ===-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<!-- === [Messaging] ===-->
<!--
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-broker</artifactId>
</dependency>
-->
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit</artifactId>
<version>1.7.2.RELEASE</version>
</dependency>
<!-- ===[Messaging with AMQP over JMS with the Apache QPID client] === -->
<dependency>
<groupId>org.apache.qpid</groupId>
<artifactId>qpid-jms-client</artifactId>
<version>0.24.0</version>
</dependency>
<!-- === [Date and Time management] ===-->
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.9.4</version>
</dependency>
<!-- === [XStream for converting classes to and from XML] === -->
<!-- NB!
XStream also needs Apache's commons-io
2017.10.15: The artifact org.apache.commons:commons-io:jar:1.3.2 has been relocated to commons-io:commons-io:jar:1.3.2
See https://mvnrepository.com/artifact/org.apache.commons/commons-io
See https://mvnrepository.com/artifact/commons-io/commons-io
-->
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.10</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<!-- === [Spring MVC and WEB (javax.servlet, JSP/JSTL] === -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.5.RELEASE</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- === [Logging and Testing] === -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
</dependencyManagement>
<profiles>
<profile>
<id>dev</id>
<properties>
<activatedProperties>dev</activatedProperties>
<datasourceURL>jdbc:oracle:thin:#h1-a-oradb10t:1521:fasitngft1</datasourceURL>
<datasourceUser>fasithub</datasourceUser>
<datasourcePassword>cH9nIiBzuS5Ho3q1bOP5</datasourcePassword>
<datasourceDriver>oracle.jdbc.OracleDriver</datasourceDriver>
<ecpServer>amqp://ec2-52-34-81-131.us-west-2.compute.amazonaws.com:5672</ecpServer>
<ecpServerSolnett>amqp://ec2-52-40-134-91.us-west-2.compute.amazonaws.com:5672</ecpServerSolnett>
<ecpServerVindnett>amqp://ec2-34-213-80-66.us-west-2.compute.amazonaws.com:5672</ecpServerVindnett>
<ecpEndpointSuffix></ecpEndpointSuffix>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>test</id>
<properties>
<activatedProperties>test</activatedProperties>
<datasourceURL>jdbc:h2:file:~/test</datasourceURL>
<datasourceUser>sa</datasourceUser>
<datasourcePassword></datasourcePassword>
<datasourceDriver>org.h2.Driver</datasourceDriver>
<ecpServer>amqp://ec2-52-34-81-131.us-west-2.compute.amazonaws.com:5672</ecpServer>
<ecpServerSolnett>amqp://ec2-52-40-134-91.us-west-2.compute.amazonaws.com:5672</ecpServerSolnett>
<ecpServerVindnett>amqp://ec2-34-213-80-66.us-west-2.compute.amazonaws.com:5672</ecpServerVindnett>
<ecpEndpointSuffix></ecpEndpointSuffix>
</properties>
</profile>
<profile>
<id>staging</id>
<properties>
<activatedProperties>staging</activatedProperties>
<datasourceURL>jdbc:oracle:thin:#h1-a-oradb10t:1521:fasitngft1</datasourceURL>
<datasourceUser>fasithub</datasourceUser>
<datasourcePassword>cH9nIiBzuS5Ho3q1bOP5</datasourcePassword>
<datasourceDriver>oracle.jdbc.OracleDriver</datasourceDriver>
<ecpServer>amqp://h1-a-ecp4end:6672</ecpServer>
<ecpServerSolnett>amqp://ec2-52-40-134-91.us-west-2.compute.amazonaws.com:5672</ecpServerSolnett>
<ecpServerVindnett>amqp://ec2-34-213-80-66.us-west-2.compute.amazonaws.com:5672</ecpServerVindnett>
<ecpEndpointSuffix>FASIT-SERVICE</ecpEndpointSuffix>
</properties>
</profile>
</profiles>
And here is the spring boot app module pom (here is where current the trial-and-error occurrs):
<?xml version="1.0" encoding="UTF-8"?>
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<!-- Alt.1: have our own parent: this is the way to go for a common jar module.
ISSUE: Spring Boot module fails to run - applicationContext fails to load!
Solution: explicitly define goal for spring-boot-maven-plugin (If you use Spring Boot as parent, you do not have to explicitly define this)
-->
<parent>
<groupId>no.statnett.fasit</groupId>
<artifactId>fasit-hub-backend</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<!-- Alt.2: have spring-boot-starter-parent as parent. This is useful for a Spring Boot app module.
ISSUE: profile management breaks - properties are not set on the Spring Boot module!
Solution: not possible without our own parent pom
-->
<!-- parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
<relativePath/>
</parent -->
<!-- Spring Boot starter properties overrule (default Java is only 1.6) -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<!-- spring.boot.version>1.5.6.RELEASE</spring.boot.version -->
</properties>
<groupId>no.statnett.fasit</groupId>
<artifactId>web</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<!-- === [Dependency Management] === -->
<dependencies>
<dependency>
<groupId>no.statnett.fasit</groupId>
<artifactId>common</artifactId>
<version>${project.version}</version>
</dependency>
<!-- === [Spring Boot Starter] === -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</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-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-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<!-- Following three dependencies where not needed with spring-boot-starter-parent as parent:
spring-boot-starter-tomcat, spring-boot-starter-thymeleaf, spring-boot-starter-data-rest
STILL GET ISSUE:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate
[org.springframework.data.rest.core.config.RepositoryRestConfiguration]:
Factory method 'config' threw exception; nested exception is java.lang.NoClassDefFoundError:
org/springframework/data/rest/core/config/RepositoryCorsRegistry
-->
<!-- === [Spring Boot JPA] === -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<exclusions>
<exclusion>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- === [Oracle driver official, manually installed] ===-->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3.0</version>
<type>pom</type>
</dependency>
<!-- === [Spring Boot Security] ===-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- === [Date and Time management] ===-->
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.3</version>
</dependency>
<!-- === [XStream for converting classes to and from XML] === -->
<!-- NB! moved to the common module, they are not needed here in the web service module! -->
</dependencies>
<!-- === [Build management for the Spring Boot module] === -->
<build>
<plugins>
<!-- === [Spring Boot Maven plugin is used for profile management] ===-->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- === [Apache Maven compiler plugin for building] ===-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
UPADTE 1:
if I add the following three dependencies to the spring app module pom:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
I instead get the following excetpion:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.rest.core.config.RepositoryRestConfiguration]: Factory method 'config' threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/data/rest/core/config/RepositoryCorsRegistry
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
... 144 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/springframework/data/rest/core/config/RepositoryCorsRegistry
I am not sure how to interpret this. Does this mean we are on the right track and just need to add some additional depedency, OR where the dependencies added needlessly and perhaps causing unnessecary problems?
The missing class now is https://docs.spring.io/spring-data/rest/docs/current/api/org/springframework/data/rest/core/config/RepositoryCorsRegistry.html
I am not sure exactly what to add as dependency to get access to this class in the right way with Spring Boot. Naturally I am reluctant to add it through a normal spring framework dependency like https://mvnrepository.com/artifact/org.springframework/spring-web/5.0.3.RELEASE since that often causes version problems (Spring Boot includes the relevant springframeworkd and should be managed totally through Spring Boot as I understand it and been told many times).
UPDATE 2:
Perhaps against better judgement – and since I'm willing to test anything until things are working – I add the following libraries which have the currently missing class.
This is of course only done after carefully checking https://mvnrepository.com/artifact/org.springframework.boot/spring-boot/1.5.9.RELEASE for exactly which core org.springframework library are used by the Spring Boot version.
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.13.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.13.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.13.RELEASE</version>
</dependency>
I now get a different exception:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.filter.OrderedHttpPutFormContentFilter]: Factory method 'httpPutFormContentFilter' threw exception; nested exception is java.lang.NoClassDefFoundError: Could not initialize class com.fasterxml.jackson.databind.ObjectMapper
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
... 26 common frames omitted
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.fasterxml.jackson.databind.ObjectMapper
at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.build(Jackson2ObjectMapperBuilder.java:588) ~[spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE]
Which leads me to add the following dependency (again after carefully checking the Spring Boot reference above to see what version of the specific library it uses):
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.4</version>
</dependency>
However, sadly and oddly enough – the same exception is still there. This means we have hit a dead end since there are no more logical libraries to include from https://mvnrepository.com/artifact/org.springframework.boot/spring-boot/1.5.9.RELEASE.
And regardless, it is not best practice to include specific core springframework library versions when working with a Spring Boot app.
So let's take a step back and look at what we need.
The Spring Boot app module contains a set of REST services.
One set of the services are only GET requests, and produces application/xml
(for integration with systems of type alpha)
Another set of the
services produces and consumes application/json (for integration with
systems of type omega).
That's it. All core service and JPA logic is in the common library module which is needed by both the web Spring Boot app module, and the worker module.
Bottom line: what spring-boot dependencies do we need to import to get this to work? Again it works perfectly fine when having the spring-boot-starter-parent as pom parent – but that is not possible in the given situation. Suffice to say it would be super to finally get this working
Cheers!
Is there some reason that the Spring Boot Starter Parent cannot be the parent of your parent pom? I see that it is commented out in your custom parent.
This setup should work:
Custom Parent pom
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.16.RELEASE</version>
</parent>
<!-- All of your customizations follow -->
<dependencies>
<!-- Define common dependencies for all child modules-->
</dependencies>
<dependencyManagement>
<!-- Define optional module dependencies with preferred versions -->
<!-- This can help the module developers to not have to deal with dependency conflicts if you handle them here -->
</dependencyManagement>
<build>
<plugins>
<!-- Define common plugin configs for all child modules -->
</plugins>
<pluginManagement>
<plugins>
<!-- Define optional plugin configs for child modules -->
</plugins>
</pluginManagement>
</build>
App pom
<parent>
<groupId>no.statnett.fasit</groupId>
<artifactId>fasit-hub-backend</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
Honestly, that should be it. You've then created a custom parent pom that inherits everything correctly from the Spring Boot Starter Parent, and you can provide all of your own profiles and other customization that you want your App module(s) to inherit.
You should not have to go through all of the trouble of recreating the dependency tree of a Spring Boot Application, and as you've noted, doing so would basically be a hellscape of dependency management.
I have now finally managed to solve this issue by brute force trial-and-error testing.
Suffice to say there are a huge number of possible of combinations of dependencies to test. As a developer this is by far among the most tedious and time-wasting task you can perform.
I am not flagging this as an acceptable answer simply because I am not happy at all with it.
Suffice to say, it would really be super with a reference set for dependency inclusions so you get exactly what you get as with the spring-boot-starter-parent. Also it does not feel like best practice to include specific core org.springframework dependencies when you are working with Spring Boot. If you are not super disciplined and doublecheck the exact library versions used by your specific Spring Boot version you will run into problems.
Best practice - as I understand it and also been told many times - is that you only import pure Spring Boot dependencies, and Spring Boot manages the rest. Evidently that sadly and suprisingly enough is not the case. If anyone has proof of the contrary, I'm all ears.
In summary these are the dependencies that solved the spring boot app module containing REST services (with both application/json and application/xml and automatic object mapping).
<!-- === [Spring Boot Starter] === -->
<!-- Compile -->
<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>
<!-- NB!
spring-boot-starter-web also needs the following [Spring Boot app fails to start without them]
These dependencies where NOT needed with spring-boot-starter-parent as parent.
Without them you e.g. get the following on Spring Boot app start:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate
[org.springframework.data.rest.core.config.RepositoryRestConfiguration]:
Factory method 'config' threw exception; nested exception is java.lang.NoClassDefFoundError:
org/springframework/data/rest/core/config/RepositoryCorsRegistry
-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.10</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.3.6.Final</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.13.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.13.RELEASE</version>
</dependency>
<!-- Provided -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- Test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

Spring Boot 1.4 QueryDSL dependencies issue

I have just updated from Spring Boot 1.3.6 to 1.4.0 and I'm getting the next problem:
The type com.querydsl.jpa.JPQLQuery cannot be resolved. It is indirectly referenced from required .class files
My pom.xml configuration is:
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
...
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>3.7.4</version>
</dependency>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-sql</artifactId>
<version>4.1.3</version>
</dependency>
Any clue?.
Thanks.
Finally, I fixed my problem updating the querydsl-jpa 3.7.4 library to QueryDSL 4 (and modifying my code). It seems like Spring Boot 1.4 is not compatible with QueryDSL 3 anymore (as Spring Data JPA 1.10 upgraded to Querydsl 4).
Thanks.
For libraries that Spring Boot provides integrations you should use a BOM dependency. Basically having this in your pom/parent pom:
<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.4.0.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
And when you specify real dependencies, drop the version:
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-sql</artifactId>
</dependency>
This guarantees compatibility since the BOM dependency is taking care of giving you the proper version.
More info here
Ulises's answer is correct and you could use
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
to mange the dependence as well. just check the dependence version managed by spring boot for right Group ID and Artifact ID

Why class SecurityEvaluationContextExtension can not be found in Spring Boot Project?

I have a spring boot based project with following declaration in pom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
and following dependencies among others
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
But seems like spring boot is not pulling in SecurityEvaluationContextExtension class on the classpath.
Am I missing a dependency or am I using an older version of spring boot?
EDIT:
I directly added the following dependency in my pom.xml and now I can see the class, but STS is showing warning : "Duplicating managed version 4.0.3.RELEASE for spring-security-data"
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-data</artifactId>
<version>4.0.3.RELEASE</version>
</dependency>
I am not shure what you mean with 'spring is not pulling in..'
But to use this extension you have to create a bean of this type see
SecurityEvaluationContextExtension
EDIT :
The warning you are getting is no problem. You can try removing the version from the dependency, because it seems available through dependencyManagement.

Resources