Spring boot with Zuul proxy crashes on Maven, while Gradle works - java

I have a Spring boot project which is built with Gradle.
I need to migrate it to Maven, which I thought would be easy (should be), but I've encountered an issue in the Zuul depedency, or to be exact: spring-cloud-starter-zuul.
When I run the Spring boot application with the annotation #EnableZuulProxy it produces the following error:
2017-03-30 00:02:57.521 WARN 11380 --- [ost-startStop-1] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
2017-03-30 00:02:57.521 INFO 11380 --- [ost-startStop-1] c.n.c.sources.URLConfigurationSource : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2017-03-30 00:02:57.532 INFO 11380 --- [ost-startStop-1] c.netflix.config.DynamicPropertyFactory : DynamicPropertyFactory is initialized with configuration sources: com.netflix.config.ConcurrentCompositeConfiguration#df85e3e
2017-03-30 00:02:57.556 ERROR 11380 --- [ost-startStop-1] o.s.b.c.embedded.tomcat.TomcatStarter : Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'org.springframework.cloud.netflix.zuul.ZuulConfiguration$ZuulFilterConfiguration': Unsatisfied dependency expressed through field 'filters'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'simpleHostRoutingFilter' defined in org.springframework.cloud.netflix.zuul.ZuulProxyConfiguration: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilter]: Factory method 'simpleHostRoutingFilter' threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/http/conn/HttpClientConnectionManager
2017-03-30 00:02:57.588 WARN 11380 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
2017-03-30 00:02:57.588 ERROR 11380 --- [ main] o.s.boot.SpringApplication : Application startup failed
The error only occurs on the Maven build, which narrow the problem to the pom.xml file vs build.gradle which does run.
After tinkering with the working build.gradle file, I've managed to produce the error when commenting out this part:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.3.RELEASE")
}
}
apply plugin: 'org.springframework.boot'
So the issue is I don't use the plugin in my maven file?
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>aaa</groupId>
<artifactId>helloZuul</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.4.3.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.4.3.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-io -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-zuul -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
<version>1.2.6.RELEASE</version>
</dependency>
</dependencies>
</project>
build.gradle
group 'aaa'
version '1.0-SNAPSHOT'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.3.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'
sourceCompatibility = 1.8
jar {
baseName = 'gs-rest-service'
version = '0.1.0'
}
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile "org.springframework.boot:spring-boot-starter-web:1.4.3.RELEASE"
compile group: 'org.apache.commons', name: 'commons-io', version: '1.3.2'
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-zuul', version: '1.2.6.RELEASE'
}
How can I make my maven project run? Or more specifically, what is the purpose of the spring boot gradle plugin?
Any help will be greatly appreciated!

You need to add dependency management in your pom.xml like below.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR6</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

I managed to get it working after a lot of trial and error.
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>aaa</groupId>
<artifactId>client</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</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-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-io -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Brixton.SR5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>

Related

DataSourceBeanCreationException: Failed to determine a suitable driver class. How to establish connection to the mongoDB from spring?

I try to implement the spring-boot project with mongoDB.
The mongoDB isn't installed locally - I use docker image for this task.
So:
docker run -d --name mongodb -e MONGO_INITDB_ROOT_USERNAME=root -e MONGO_INITDB_ROOT_PASSWORD=pass -p 27017:27017
docker image installed successfully and I able to enter into docker shell with
docker exec -it {conteinerId} bash
Now, I try to execute spring-boot application.
application.properties:
spring.data.mongodb.database=proxy_db
spring.data.mongodb.host=localhost
spring.data.mongodb.username=root
spring.data.mongodb.password=pass
spring.data.mongodb.port=27017
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.6.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.task</groupId>
<artifactId>task</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>crud</name>
<description>User CRUD endpoints</description>
<properties>
<java.version>11</java.version>
<spring.boot.version>2.6.6</spring.boot.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>${spring.boot.version}</version>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring.boot.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
</plugin>
</plugins>
</build>
</project>
After launching I received warning:
2023-01-30 19:53:41.941 WARN 12208 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: 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 org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
And as result, error:
APPLICATION FAILED TO START
Description:
Failed to configure a DataSource: 'url' attribute is not specified and
no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
As I understand - the spring can't establish the connection with the database.
So, how to correctly manage MongoDB in the spring-boot + docker?
You are using the wrong property names, eg url, hence "Failed to configure a DataSource: 'url' attribute is not specified."
Try these:
spring.datasource.url = mongodb://localhost:27017/proxy_db
spring.datasource.username = root
spring.datasource.password = password
Optionally you may need this:
spring.datasource.driver-class-name = com.mongodb.Mongo
Also there appear to be missing/incorrect dependencies:
<!-- https://mvnrepository.com/artifact/org.mongodb/mongo-java-driver -->
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.12.11</version>
</dependency>

Incompatible dependencies in Spring Boot (Maven)

I have started creating a RESTful API using Spring Boot. I haven't touched Spring in 2 years. I am using Maven. I have the main class:
package com.tsakirogf.smartapi;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class SmartapiApplication
{
public static void main(String[] args)
{
SpringApplication.run(PeopleapiApplication.class, args);
}
}
I have a Controller, Model and Service. This 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 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.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.tsakirogf</groupId>
<artifactId>peopleapi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>smartapi</name>
<description>Technical Test</description>
<properties>
<java.version>11</java.version>
<!-- <tomcat.version>8.5.63</tomcat.version>-->
</properties>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.200</version>
<!-- <scope>test</scope>-->
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.4.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.4.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.4.2</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>2.3.6.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
The project is building successfully and the mvn clean and mvn install commands run successfully as well.
The problem is that when I am trying to run it in IntelliJ I get this error:
2021-02-11 18:19:42.692 ERROR 14584 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
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.apache.catalina.authenticator.AuthenticatorBase.startInternal(AuthenticatorBase.java:1355)
The following method did not exist:
'java.lang.String javax.servlet.ServletContext.getVirtualServerName()'
The method's class, javax.servlet.ServletContext, is available from the following locations:
jar:file:/F:/Workspace/Uni/SoftwareEngineer/peopleapi/lib/javax.servlet.jar!/javax/servlet/ServletContext.class
jar:file:/C:/Users/Fotis/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.41/tomcat-embed-core-9.0.41.jar!/javax/servlet/ServletContext.class
The class hierarchy was loaded from the following locations:
javax.servlet.ServletContext: file:/F:/Workspace/Uni/SoftwareEngineer/peopleapi/lib/javax.servlet.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of javax.servlet.ServletContext
Process finished with exit code 1
Any thoughts or directions I should move to? I have tried to synchronize dependencies and tried the latest and RELEASE packages in the pom. I have also deleted the whole m2 repo (twice).
Your problem is F:/Workspace/Uni/SoftwareEngineer/peopleapi/lib/javax.servlet.jar. Check why you have that JAR in your classpath (most likely it comes through some script or so). This seems to be an older version than the one you're referencing in your pom.xml

Getting error while running springboot application

Not able to run spring boot application
Tried removing contents of /C:/Users/SaurKumar/.m2/repository/org/springframework/data/spring-data-commons/2.1.10.RELEASE/spring-data-commons-2.1.10.RELEASE.jar
:: Spring Boot :: (v2.1.8.RELEASE)
2019-09-08 05:22:05.217 INFO 2420 --- [ main] i.j.c.CourseApiDataApplication : Starting CourseApiDataApplication on BLRLW8166 with PID 2420 (C:\Users\SaurKumar\Downloads\course-api-data\course-api-data\target\classes started by saurkumar in C:\Users\SaurKumar\Downloads\course-api-data\course-api-data)
2019-09-08 05:22:05.222 INFO 2420 --- [ main] i.j.c.CourseApiDataApplication : No active profile set, falling back to default profiles: default
2019-09-08 05:22:06.110 INFO 2420 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-09-08 05:22:06.215 ERROR 2420 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
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.data.jpa.repository.config.JpaRepositoryConfigExtension.postProcess(JpaRepositoryConfigExtension.java:121)
The following method did not exist:
org.springframework.data.repository.config.RepositoryConfigurationSource.getAttribute(Ljava/lang/String;)Ljava/lang/String;
The method's class, org.springframework.data.repository.config.RepositoryConfigurationSource, is available from the following locations:
jar:file:/C:/Users/SaurKumar/.m2/repository/org/springframework/data/spring-data-commons/2.1.10.RELEASE/spring-data-commons-2.1.10.RELEASE.jar!/org/springframework/data/repository/config/RepositoryConfigurationSource.class
It was loaded from the following location:
file:/C:/Users/SaurKumar/.m2/repository/org/springframework/data/spring-data-commons/2.1.10.RELEASE/spring-data-commons-2.1.10.RELEASE.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.springframework.data.repository.config.RepositoryConfigurationSource
Process finished with exit code 1
-----------------------------------------
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.1.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>io.javabrains</groupId>
<artifactId>course-api-data</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>course-api-data</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.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.11.7.RELEASE</version>
</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>
From the logs, it seems Spring is picking a different version for groupId org.springframework.data than the one provided with spring-data-jpa. If you could match the versions of spring-boot-starter-web and spring-data-jpa, it should work.
Quick fix being: Remove the version number for spring-data-jpa and it will by default take the latest version, which in your case is 2.1.10.RELEASE.

Error starting ApplicationContext in Spring Boot App

I am trying with simple spring boot application. I am facing problem on starting an application on ApplicationContext.
2017-04-26 11:17:31.101 WARN 14528 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'standardJacksonObjectMapperBuilderCustomizer' defined in class path resource
[org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration$Jackson2ObjectMapperBuilderCustomizerConfiguration.class]: Unsatisfied dependency expressed through method 'standardJacksonObjectMapperBuilderCustomizer' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring.jackson-org.springframework.boot.autoconfigure.jackson.JacksonProperties': Initialization of bean failed; nested exception is javax.validation.ValidationException: Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath.
2017-04-26 11:17:31.116 INFO 14528 --- [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-04-26 11:17:31.121 ERROR 14528 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
I got above errors while starting an application. I am using spring boot 1.5.1.RELEASE version.
Kindly do needful.
EDIT 1
EDIT 2
package com.hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class HelloWorld{
public static void main(String[] args) {
// TODO Auto-generated method stub
SpringApplication.run(HelloWorld.class, args);
}
}
It seems like Jackson libraries not available for this boot project.
Either add Jackson libraries manually or add the following dependencies which will internally import Jackson libraries.
<?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>
<name>helloWorld</name>
<version>0.0.0-SNAPSHOT</version>
<groupId>com.test</groupId>
<artifactId>test</artifactId>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
</parent>
<packaging>jar</packaging>
<properties>
<dozer.version>5.4.0</dozer.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
I solved the problem by excluding hibernate-validator dependency in pom.xml. It is working fine without any issues.
Resolved the issue by adding the below dependency for Jackson:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>1.2.1.RELEASE</version>
</dependency>
Also make sure to remove classpath entries for Jackson

org.springframework.boot.web.support does not exist

I'm changing build systems from maven to gradle for a spring boot project. I get this stacktrace
19:03:08: Executing external task 'bootRun'...
/home/dac/proj/spring-boot-master/spring-boot-samples/spring-boot-sample-jetty-jsp/src/main/java/sample/jetty/jsp/SampleJettyJspApplication.java:22: error: package org.springframework.boot.web.support does not exist
import org.springframework.boot.web.support.SpringBootServletInitializer;
^
/home/dac/proj/spring-boot-master/spring-boot-samples/spring-boot-sample-jetty-jsp/src/main/java/sample/jetty/jsp/SampleJettyJspApplication.java:25: error: cannot find symbol
public class SampleJettyJspApplication extends SpringBootServletInitializer {
^
symbol: class SpringBootServletInitializer
/home/dac/proj/spring-boot-master/spring-boot-samples/spring-boot-sample-jetty-jsp/src/main/java/sample/jetty/jsp/SampleJettyJspApplication.java:27: error: method does not override or implement a method from a supertype
#Override
^
3 errors
:compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 2.334 secs
Compilation failed; see the compiler error output for details.
19:03:10: External task execution finished 'bootRun'.
My build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:1.3.6.RELEASE"
classpath 'org.springframework:springloaded:1.2.5.RELEASE'
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'rebel'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath group: 'org.zeroturnaround', name: 'gradle-jrebel-plugin', version: '1.1.3'
}
}
jar {
baseName = 'gs-spring-boot'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
// tag::jetty[]
compile("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
}
compile("org.springframework.boot:spring-boot-starter-jetty")
// end::jetty[]
// tag::actuator[]
compile("org.springframework.boot:spring-boot-starter-actuator")
testCompile("org.springframework.boot:spring-boot-starter-test")
testCompile("junit:junit")
}
// change default IntelliJ output directory for compiling classes
idea {
module {
inheritOutputDirs = false
outputDir = file("$buildDir/classes/main/")
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
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>
<parent>
<!-- Your own application should inherit from spring-boot-starter-parent -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-samples</artifactId>
<version>1.4.0.BUILD-SNAPSHOT</version>
</parent>
<artifactId>spring-boot-sample-jetty-jsp</artifactId>
<packaging>war</packaging>
<name>Spring Boot Jetty JSP Sample</name>
<description>Spring Boot Jetty JSP Sample</description>
<url>http://projects.spring.io/spring-boot/</url>
<organization>
<name>Pivotal Software, Inc.</name>
<url>http://www.spring.io</url>
</organization>
<properties>
<main.basedir>${basedir}/../..</main.basedir>
<m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-el</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
<!--<scope>provided</scope>-->
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>apache-jsp</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>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
</plugins>
</build>
</project>
How should I make the package available to gradle?
You are using org.springframework.boot.context.web.SpringBootServletInitializer this is deprecated. Instead:
Use
org.springframework.boot.web.support.SpringBootServletInitializer
For SpringBoot 2.0
org.springframework.boot.web.servlet.support.SpringBootServletInitializer
It's probably an import issue in your source code - your Gradle build script uses Spring Boot 1.3.6.RELEASE in which SpringBootServletInitializer has the following fully qualified name:
org.springframework.boot.context.web.SpringBootServletInitializer
Your Maven pom.xml, however, uses Spring Boot 1.4.0.BUILD-SNAPSHOT, in which the package name was changed to:
org.springframework.boot.web.support.SpringBootServletInitializer
So if you go to your SampleJettyJspApplication and change the import to
import org.springframework.boot.context.web.SpringBootServletInitializer;
everything should be fine.
Alternatively, you could alter your Gradle build script to import 1.4.0.BUILD-SNAPSHOT, but that would require adding Spring's snapshot repository:
buildscript {
repositories {
maven.url "http://repo.spring.io/snapshot"
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.0.BUILD-SNAPSHOT")
}
}
You should use the same spring boot version 1.4.0.BUILD-SNAPSHOT as in maven. org.springframework.boot.web.support.SpringBootServletInitializer was introduced since 1.4.0 that's why gradle cannot find it.
org.springframework.boot.web.support.SpringBootServletInitializer
is deprecated.
use below instead:
org.springframework.boot.web.servlet.support.SpringBootServletInitializer

Categories