Gradle doesn't see Spring packages, but have a dependency declared - java

I'm working on my new project. But when I try to build it, gradle return the error:
error: package org.springramework.transaction does not exist
import org.springframework.transaction.PlatformTransactionManager;
and
error: package org.springramework.orm.hibernate5 does not exist
import org.springframework.orm.hibernate5.HibernateTransactionManager;
Here is my build.gradle:
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.bmuschko:gradle-tomcat-plugin:2.4.1'
}
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'com.bmuschko.tomcat'
compileJava.options.encoding = 'UTF-8'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
def tomcatVersion = '9.0.22'
dependencies {
testImplementation 'junit:junit:4.12'
tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
"org.apache.tomcat.embed:tomcat-embed-logging-juli:8.5.2",
"org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion},"
testCompile group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3'
testCompile group: 'org.mockito', name: 'mockito-all', version: '1.8.4'
}
tomcat {
httpProtocol = 'org.apache.coyote.http11.Http11Nio2Protocol'
ajpProtocol = 'org.apache.coyote.ajp.AjpNio2Protocol'
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.apache.tomcat:tomcat-dbcp:9.0.22'
implementation 'org.postgresql:postgresql:42.2.6'
implementation 'org.springframework:spring-context:5.1.8.RELEASE'
implementation 'org.springframework:spring-webmvc:5.1.8.RELEASE'
implementation 'org.springframework:spring-orm:5.1.8.RELEASE'
implementation 'org.springframework:spring-tx:5.1.8.RELEASE'
implementation 'org.hibernate:hibernate-core:5.4.1.Final'
}
There is no error about spring context imports.
I know, this is very strange, but in folder
~/.gradle/caches/modules-2/files-2.1/org.springframework there are both spring-orm and spring-tx folder with jars.
What am I doing wrong?

Related

Spring Boot (Gradle) app deployed to Google App Engine returns 404 Not Found

I have a Spring Boot (2.1.7) (Gradle project) that I want to deploy to Google App Engine.
I am able to successfully deploy the app (using the documentation found here) but when visiting the app url it returns a 404 Not Found screen:
<html><head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>404 Not Found</title>
</head>
<body text=#000000 bgcolor=#ffffff>
<h1>Error: Not Found</h1>
</body></html>
Here's what my build.gradle file looks like:
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.google.cloud.tools:appengine-gradle-plugin:2.1.0'
classpath 'org.akhikhl.gretty:gretty:+'
}
}
plugins {
id 'org.springframework.boot' version '2.1.7.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'org.akhikhl.gretty'
apply plugin: 'com.google.cloud.tools.appengine'
group = 'com.company'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
configurations.all {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
exclude group: 'org.slf4j', module: 'jul-to-slf4j'
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-jetty'
providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
providedCompile 'com.google.appengine:appengine:+'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
gretty {
httpPort = 8080
contextPath = '/'
servletContainer = 'jetty9' // What App Engine Flexible uses
}
appengine {
deploy {
version = "3"
projectId = "apprealtest"
stopPreviousVersion = true // default - stop the current version
promote = true // default - & make this the current version
}
}
Here is what my {projectRoot}/src/main/appengine/app.yaml file looks like:
runtime: java
env: flex
runtime_config: # Optional
jdk: openjdk8
handlers:
- url: /.*
script: this field is required, but ignored
manual_scaling:
instances: 1
This is what my {projectRoot}/src/main/webapp/WEB-INF/appengine-web.xml file looks like:
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<runtime>java8</runtime>
<threadsafe>true</threadsafe>
</appengine-web-app>
This is what the {projectRoot}/src/main/java/com/company/hello/HelloApplication.java looks like:
package com.company.hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class HelloApplication {
public static void main(String[] args) {
SpringApplication.run(HelloApplication.class, args);
}
}
This is what the {projectRoot}/src/main/java/com/company/hello/HelloController.java looks like:
package com.company.hello;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
#RestController
public class HelloController {
#GetMapping("/")
public String get() {
return System.currentTimeMillis() + "";
}
#GetMapping("/greeting")
public String getGreeting() {
return "Greetings!";
}
}
I'm making the call to https://apprealtest.appspot.com and https://apprealtest.appspot.com/greeting.
What am I doing wrong?
To deploy it in GAE Standard you can download this official SpringBoot for App Engine Standard sample.
The instructions are for maven but to do it with Gradle you can simply add this build.gradle file:
buildscript { // Configuration for building
repositories {
jcenter() // Bintray's repository - a fast Maven Central mirror & more
mavenCentral()
}
dependencies {
classpath 'com.google.cloud.tools:appengine-gradle-plugin:1.+' // Latest 1.x.x release
}
}
repositories { // repositories for Jar's you access in your code
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots' // SNAPSHOT repository (if needed)
}
mavenCentral()
jcenter()
}
apply plugin: 'java' // standard Java tasks
apply plugin: 'war' // standard Web Archive plugin
apply plugin: 'com.google.cloud.tools.appengine' // App Engine tasks
apply plugin: 'maven-publish'
dependencies {
compile 'com.google.appengine:appengine-api-1.0-sdk:+' // Latest App Engine Api's
compile 'org.springframework.boot:spring-boot-starter-web:2.1.1.RELEASE'
testCompile 'org.springframework.boot:spring-boot-starter-test:2.1.1.RELEASE'
providedCompile 'org.slf4j:jul-to-slf4j:1.7.25'
providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
}
configurations.all {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
exclude group: 'org.slf4j', module: 'jul-to-slf4j'
}
group = 'com.google.appengine.demos'
version = '0.0.1-SNAPSHOT'
description = 'springboot-appengine-standard'
sourceCompatibility = '1.8'
publishing {
publications {
maven(MavenPublication) {
from(components.java)
}
}
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
And you can deploy it with gradle appengineDeploy.
I tested it myself and it worked. If you want to do it in GAE Flexible the corresponding sample would be this one which also has instructions for Maven so you would have to do the necessary migration to Gradle.
As I have not found a complete example of spring boot with the Gradle build tool.
Added a complete example with updated spring boot version 2.2.3 and AppEngine Gradle plugin 2.2.0.
buildscript {
repositories {
mavenCentral()
maven{
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'com.google.cloud.tools:appengine-gradle-plugin:2.2.0'
}
}
plugins {
id 'java'
id 'war'
id 'org.springframework.boot' version '2.2.3.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
}
repositories {
mavenCentral()
jcenter()
}
configurations.all {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
exclude group: 'org.slf4j', module: 'jul-to-slf4j'
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
compile "com.google.appengine:appengine-api-1.0-sdk:+"
providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.0.1'
providedCompile "com.google.appengine:appengine-api-stubs:+"
providedCompile "com.google.appengine:appengine-testing:+"
providedCompile 'org.slf4j:jul-to-slf4j:1.7.25'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
compile group: 'net.bytebuddy', name: 'byte-buddy', version: '1.10.3'
}
apply plugin: "com.google.cloud.tools.appengine"
appengine { // App Engine tasks configuration
run { // local (dev_appserver) configuration (standard environments only)
jvmFlags = ['-Ddatastore.backing_store=../../src/main/webapp/WEB-
INF/appengine-generated/local_db.bin', '-Dappengine.fullscan.seconds=5']
port = 8812 // default
}
deploy { // deploy configuration\
stopPreviousVersion = false // default - stop the current version
promote = false // default - & make this the current version
version = 'pr'
projectId = ''
}
}
This repo has a complete example and the test case for its controller. hope it would help.

java.lang.AbstractMethodError: Configuration error when trying to execute test using Spring Boot [duplicate]

I'm a neophyte to Spring Boot, and I wanted to change my default logger to log4j2, since it has a higher throughput rate than logback.
Here's my Gradle script. As you can see, I am using Spring Boot 2.0.3, and to disable the default logger I used exclude module(logback and spring boot starter logger) after Spring Boot Web. I am compiling log4j at the bottom of my script.
buildscript {
ext {
springBootVersion = '2.0.3.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'app'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
}
ext {
vaadinVersion = '8.4.1'
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-rest')
providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
compile('org.springframework.boot:spring-boot-starter-web') {
exclude module: "spring-boot-starter-logging"
exclude module: "logback-classic"
}
compile('org.springframework.boot:spring-boot-starter-webflux')
compile('org.springframework.boot:spring-boot-starter-jdbc')
compile('org.springframework.boot:spring-boot-starter-log4j2')
compile('com.vaadin:vaadin-spring-boot-starter')
runtime('org.springframework.boot:spring-boot-devtools')
compileOnly('org.springframework.boot:spring-boot-configuration-processor')
compileOnly('org.projectlombok:lombok')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('io.projectreactor:reactor-test')
testCompile('org.springframework.security:spring-security-test')
testCompile 'junit:junit:4.12'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.1'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.1'
// https://mvnrepository.com/artifact/com.h2database/h2
//compile group: 'com.h2database', name: 'h2', version: '1.0.60'
testCompile group: 'com.h2database', name: 'h2', version: '1.3.148'
}
dependencyManagement {
imports {
mavenBom "com.vaadin:vaadin-bom:${vaadinVersion}"
}
}
This is my Spring Boot application.
package app.clothapp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class ClothappApplication {
public static void main(String[] args) {
SpringApplication.run(ClothappApplication.class, args);
}
}
However, when I run my Spring Boot application, it provides me with an AbstractMethodError. I've read some other SO questions, and apparently some class has inappropriately changed since it was last compiled. Could anyone provide some help?
Exception in thread "main" java.lang.AbstractMethodError: org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(Lorg/apache/logging/log4j/core/config/ConfigurationSource;)Lorg/apache/logging/log4j/core/config/Configuration;
at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:472)
at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:442)
at org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:254)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:419)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:138)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:147)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:41)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:175)
at org.apache.commons.logging.LogFactory$Log4jLog.<clinit>(LogFactory.java:199)
at org.apache.commons.logging.LogFactory$Log4jDelegate.createLog(LogFactory.java:166)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:109)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:99)
at org.springframework.boot.SpringApplication.<clinit>(SpringApplication.java:198)
at app.clothapp.ClothappApplication.main(ClothappApplication.java:10)
Thank you.
There will be more than one transitive dependency on spring-boot-starter-logging. For example:
spring-boot-starter-security depends on spring-boot-starter
spring-boot-starter depends on spring-boot-starter-logging
You can run gradle dependencies to confirm.
In order to exlcude a dependency from everywhere, use:
configurations {
all*.exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
}
Spring suggest including the dependency on spring-boot-starter and then excluding the logger from there, something like:
compile('org.springframework.boot:spring-boot-starter') {
exclude module: "spring-boot-starter-logging"
}
But I have found that not all Spring dependencies are so well behaved, so the above sometimes fails when there are explicit dependencies on Spring logging elsewhere.

What's wrong with my attempt to change Spring's default logger to log4j2?

I'm a neophyte to Spring Boot, and I wanted to change my default logger to log4j2, since it has a higher throughput rate than logback.
Here's my Gradle script. As you can see, I am using Spring Boot 2.0.3, and to disable the default logger I used exclude module(logback and spring boot starter logger) after Spring Boot Web. I am compiling log4j at the bottom of my script.
buildscript {
ext {
springBootVersion = '2.0.3.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'app'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
}
ext {
vaadinVersion = '8.4.1'
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-rest')
providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
compile('org.springframework.boot:spring-boot-starter-web') {
exclude module: "spring-boot-starter-logging"
exclude module: "logback-classic"
}
compile('org.springframework.boot:spring-boot-starter-webflux')
compile('org.springframework.boot:spring-boot-starter-jdbc')
compile('org.springframework.boot:spring-boot-starter-log4j2')
compile('com.vaadin:vaadin-spring-boot-starter')
runtime('org.springframework.boot:spring-boot-devtools')
compileOnly('org.springframework.boot:spring-boot-configuration-processor')
compileOnly('org.projectlombok:lombok')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('io.projectreactor:reactor-test')
testCompile('org.springframework.security:spring-security-test')
testCompile 'junit:junit:4.12'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.1'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.1'
// https://mvnrepository.com/artifact/com.h2database/h2
//compile group: 'com.h2database', name: 'h2', version: '1.0.60'
testCompile group: 'com.h2database', name: 'h2', version: '1.3.148'
}
dependencyManagement {
imports {
mavenBom "com.vaadin:vaadin-bom:${vaadinVersion}"
}
}
This is my Spring Boot application.
package app.clothapp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class ClothappApplication {
public static void main(String[] args) {
SpringApplication.run(ClothappApplication.class, args);
}
}
However, when I run my Spring Boot application, it provides me with an AbstractMethodError. I've read some other SO questions, and apparently some class has inappropriately changed since it was last compiled. Could anyone provide some help?
Exception in thread "main" java.lang.AbstractMethodError: org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(Lorg/apache/logging/log4j/core/config/ConfigurationSource;)Lorg/apache/logging/log4j/core/config/Configuration;
at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:472)
at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:442)
at org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:254)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:419)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:138)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:147)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:41)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:175)
at org.apache.commons.logging.LogFactory$Log4jLog.<clinit>(LogFactory.java:199)
at org.apache.commons.logging.LogFactory$Log4jDelegate.createLog(LogFactory.java:166)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:109)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:99)
at org.springframework.boot.SpringApplication.<clinit>(SpringApplication.java:198)
at app.clothapp.ClothappApplication.main(ClothappApplication.java:10)
Thank you.
There will be more than one transitive dependency on spring-boot-starter-logging. For example:
spring-boot-starter-security depends on spring-boot-starter
spring-boot-starter depends on spring-boot-starter-logging
You can run gradle dependencies to confirm.
In order to exlcude a dependency from everywhere, use:
configurations {
all*.exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
}
Spring suggest including the dependency on spring-boot-starter and then excluding the logger from there, something like:
compile('org.springframework.boot:spring-boot-starter') {
exclude module: "spring-boot-starter-logging"
}
But I have found that not all Spring dependencies are so well behaved, so the above sometimes fails when there are explicit dependencies on Spring logging elsewhere.

Run as spring boot app is not working where as run as java app working

I am using STS.
This is my main class:
#EnableZuulProxy
#SpringBootApplication
public static void main(String[] args) {
try {
SpringApplication.run(DevProxyApp.class, args);
}catch(Exception e) {
}
}
}
Below is my build.gradle :
buildscript {
ext {
springBootVersion = '2.0.2.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
plugins {
id 'pmd'
id 'org.sonarqube' version '2.6.2'
}
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'jacoco'
mainClassName = 'com.siemens.mindsphere.devproxy.DevProxyApp'
group = 'mindsphere'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
ext {
springCloudVersion = 'Finchley.BUILD-SNAPSHOT'
}
jar {
baseName = 'sdk-devproxy'
doLast {
}
destinationDir = file("$buildDir/libs/mindsphere/sdk-devproxy/$project.version/")
}
dependencies {
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-parent', version: 'Edgware.SR3', ext: 'pom'
compile('org.springframework.cloud:spring-cloud-starter-oauth2')
compile('org.springframework.cloud:spring-cloud-starter-netflix-zuul')
compile('org.springframework.boot:spring-boot-starter-web')
compile group: 'com.auth0', name: 'java-jwt', version: '3.3.0'
compile('com.auth0:java-jwt')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.security:spring-security-test')
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
i have also tried with below dependencies:
dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter-parent', version: '1.2.1.RELEASE', ext: 'pom'
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-parent', version: 'Edgware.SR3', ext: 'pom'
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-oauth2', version: '1.0.0.RELEASE'
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-zuul', version: '1.4.4.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '1.5.9.RELEASE'
implementation 'org.slf4j:slf4j-api:1.7.25'
compile group: 'com.auth0', name: 'java-jwt', version: '3.3.0'
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.security:spring-security-test')
}
Whenever I run the application as spring boot app its giving me the below error:
Error: Could not find or load main class com.siemens.mindsphere.devproxy.DevProxyApp
While running as java application, it is working starting but with this kind of launch functionalities(oauth2, zuul routing functionalities) are not working.
i have tried below things, but still issue is there:
Refreshing , rebuilding, updating gradle
removing all the dependencies manually, removing gradle repo manually
installed new STS.
If you need any other info to address this issue please let me know.
FYI Previously it was a maven project and working fine, now I am making it as gradle project by adding build.gradle, gradle project and etc. and removed pom.xml. Gradle build is happening properly.
Is the issue with any jar compatibility ????
Try to add a manifest attribute:
jar {
manifest {
attributes(
'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
'Main-Class': 'com.siemens.mindsphere.devproxy.DevProxyApp'
)
}
}
Try to downgrade the springBootVersion.
I had this issue and this resolved it.

Caused by: java.lang.ClassNotFoundException: org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter

I am using spring Boot.I created Spring boot gradle application.I got following error.
Caused by: java.lang.ClassNotFoundException: org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter
build.gradle
buildscript {
ext {
springBootVersion = '1.3.2.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.2.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
jar {
baseName = 'demo'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.7
targetCompatibility = 1.7
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-mongodb')
testCompile('org.springframework.boot:spring-boot-starter-test')
compile group: 'org.springframework', name: 'spring-web', version: '4.0.0.RELEASE'
compile group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version: '1.9.12'
compile group: 'org.codehaus.jackson', name: 'jackson-core-asl', version: '1.9.12'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.2.2'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.2.2'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.2.2'
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7'
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.9'
}
Am I missing any dependency in build.gradle?
How to solve this?
You are including two different versions of the jackson lib. For Spring 4+ use the com.fasterxml.jackson.core like you have. Remove the two org.codehaus.jackson dependencies.

Categories

Resources