Trying to convert existing spring app to springboot app - java

I have existing spring app which i am trying to convert to springboot app. Existing app has gradle as dependency/build manager.
So far I have performed following steps:
Following dependency has been added in existing build.gradle file
dependencies {
compileOnly("org.springframework.boot:spring-boot-starter-web:2.0.3.RELEASE") {
exclude group: 'com.fasterxml.jackson.core', module: 'jackson-databind'
}
}
Add an application entry point
.
#SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
So far no problem in building the project with gradle but when I try to up the project by executing the following command:
java -jar myapplication.jar
I am getting the following exception:
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
at com.netspend.partnerconnection.ws.PartnerConnectionApplication.main(PartnerConnectionApplication.java:9)
... 8 more
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:93)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 9 more
I am using gradle 4.10

Do NOT use compileOnly configuration for dependencies needed at runtime (see here for dependency types explanation)
Use implementation configuration, as Spring classes are needed at runtime.
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web:2.0.3.RELEASE") {
exclude group: 'com.fasterxml.jackson.core', module: 'jackson-databind'
}
}

Related

Unable to load the voltage class java.lang.NoClassDefFoundError: com/voltage/securedata/enterprise/VeException

I am trying to encrypt / decrypt messages using libvibesimplejava.so of 6.21 version where I have added the dependencies to load the jar from system path when I deployed to dev instance it's throwing this error:
Caused by: java.lang.NoClassDefFoundError: com/voltage/securedata/enterprise/VeException
Caused by: java.lang.ClassNotFoundException: com.voltage.securedata.enterprise.VeException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_181]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_181]
Below is the code for library instantiation
Loading Library -
static {
System.load("src/main/resources/****/libvibesimplejava.so");
}
Library context instanitiation -
LibraryContext library = new LibraryContext.Builder()
.setPolicyURL(policyURL)
.setFileCachePath(cachePath)
.setTrustStorePath(trustStorePath)
.setClientIdProduct("****",
"***")
.build();
Pom file -
<dependency>
<groupId>vibesimplejava</groupId>
<artifactId>vibesimplejava</artifactId>
<version>6.21.0.0</version>
<scope>system</scope>
<systemPath>${basedir}/src/main/resources/****/lib/vibesimplejava.jar</systemPath>
</dependency>
Why it is failing to load the class in dev? Could any one suggest me the way to resolve this issue?

Spring Boot can not find AutoConfigurationReportLoggingInitializer

When I build my jar, I get ClassNotFoundException for AutoConfigurationReportLoggingInitializer.
This class is not in Spring libraries built by Gradle and also the class is not necessary for running in IDE. Is it possible to disable searching for this class? Or do you have some other solution?
EXCEPTION:
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.autoconfigure.logging.AutoConfigurationReportLoggingInitializer
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:284)
at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:438)
... 10 more
build.gradle:
plugins {
id 'org.springframework.boot' version '2.3.3.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.1'
}
Try adding the spring-boot-starter dependency which includes spring-boot-starter-logging which has the class you are missing

java.lang.NoClassDefFoundError: org/apache/flink/streaming/connectors/rabbitmq/common/RMQConnectionConfig in flink job

I am commit flink(v1.10.0) job to my cluster, but shows this error:
System.out: (none)
System.err: (none)
at org.apache.flink.client.program.OptimizerPlanEnvironment.generateException(OptimizerPlanEnvironment.java:149)
at org.apache.flink.client.program.OptimizerPlanEnvironment.getPipeline(OptimizerPlanEnvironment.java:89)
at org.apache.flink.client.program.PackagedProgramUtils.getPipelineFromProgram(PackagedProgramUtils.java:101)
at org.apache.flink.client.program.PackagedProgramUtils.createJobGraph(PackagedProgramUtils.java:56)
at org.apache.flink.runtime.webmonitor.handlers.utils.JarHandlerUtils$JarHandlerContext.toJobGraph(JarHandlerUtils.java:128)
at org.apache.flink.runtime.webmonitor.handlers.JarRunHandler.lambda$getJobGraphAsync$6(JarRunHandler.java:138)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1604)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoClassDefFoundError: org/apache/flink/streaming/connectors/rabbitmq/common/RMQConnectionConfig$Builder
at org.myorg.quickstart.StreamingJob.i(StreamingJob.java:123)
at org.myorg.quickstart.StreamingJob.main(StreamingJob.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.flink.client.program.PackagedProgram.callMainMethod(PackagedProgram.java:321)
at org.apache.flink.client.program.PackagedProgram.invokeInteractiveModeForExecution(PackagedProgram.java:205)
at org.apache.flink.client.program.OptimizerPlanEnvironment.getPipeline(OptimizerPlanEnvironment.java:79)
... 8 more
Caused by: java.lang.ClassNotFoundException: org.apache.flink.streaming.connectors.rabbitmq.common.RMQConnectionConfig$Builder
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
at org.apache.flink.util.ChildFirstClassLoader.loadClass(ChildFirstClassLoader.java:60)
at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
... 17 more
it seems like could not find RMQConnectionConfig in runtime, how to add the jar in system wide and make my task jar small and thin? This is my gradle.build dependencies:
dependencies {
// --------------------------------------------------------------
// Compile-time dependencies that should NOT be part of the
// shadow jar and are provided in the lib folder of Flink
// --------------------------------------------------------------
compile "org.apache.flink:flink-java:${flinkVersion}"
compile "org.apache.flink:flink-streaming-java_${scalaBinaryVersion}:${flinkVersion}"
// --------------------------------------------------------------
// Dependencies that should be part of the shadow jar, e.g.
// connectors. These must be in the flinkShadowJar configuration!
// --------------------------------------------------------------
//flinkShadowJar "org.apache.flink:flink-connector-kafka-0.11_${scalaBinaryVersion}:${flinkVersion}"
compile "log4j:log4j:${log4jVersion}"
compile "org.slf4j:slf4j-log4j12:${slf4jVersion}"
compile "com.rabbitmq:amqp-client:4.2.0"
compile "com.alibaba:fastjson:1.2.57"
compile "org.apache.flink:flink-connector-rabbitmq_${scalaBinaryVersion}:1.10.0"
}
if you want the jar contains to dist.jar file,you should write dependencies like this:
flinkShadowJar "com.rabbitmq:amqp-client:4.2.0"
flinkShadowJar "com.alibaba:fastjson:1.2.57"
flinkShadowJar "org.apache.flink:flink-connector-rabbitmq_${scalaBinaryVersion}:1.10.0"
it will package the dependencies to dist jar file and using at runtime.

How to prevent ALL of Jackson auto-config in Spring?

Context
I have a situation where I do not control the main of the application nor the libraries on the class path. I am extending (via a plug-in API) an existing Swing application. The goal of my project is to make the information inside of that legacy application available through a HTTP API to then interface it via a web application.
Technical situation
The application in question has already Jackson in the class path in version 2.7. I am trying to use Spring Boot version 2, which is built against Jackson 2.8. When I start the server, Spring is unable to initialise because it is trying to configure Jackson stuff, using classes and methods that did not exist in 2.7.
What I would like to do is prevent Spring from automatically configuring anything Jackson-related and let me provide my own content negotiator.
I already tried
#SpringBootApplication(
exclude = arrayOf(JacksonAutoConfiguration::class)
)
but it does not work.
Digging into Spring code, I see places where it is hard-coded inside of AllEncompassingFormHttpMessageConverter that is Jackson is on the class path, it should create new objects (that cause the exception in question), despite the fact I am excluding the Jackson configuration in my Spring Boot application.
private static final boolean jackson2Present =
ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", AllEncompassingFormHttpMessageConverter.class.getClassLoader()) &&
ClassUtils.isPresent("com.fasterxml.jackson.core.JsonGenerator", AllEncompassingFormHttpMessageConverter.class.getClassLoader());
and then later:
if (jackson2Present) {
addPartConverter(new MappingJackson2HttpMessageConverter());
}
Project as it is now
Here is a link to GitHub, to the right branch.
https://github.com/Adeynack/finances/tree/spring--jackson-init-bypass/backend
The project in this state causes the error. Run ./gradlew server-standalone:run.
Complete error log
The errors I get are the following:
2017-11-30 17:15:54,475 | ERROR | main | o.springframework.boot.SpringApplication | Application startup failed
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:137)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:327)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1245)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1233)
at com.github.adeynack.finances.backend.serverStandalone.FinancesServerStandalone.main(FinancesServerStandalone.kt:10)
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:114)
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:81)
at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:527)
at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:185)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:161)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:134)
... 8 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'httpPutFormContentFilter' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.filter.OrderedHttpPutFormContentFilter]: Factory method 'httpPutFormContentFilter' threw exception; nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/exc/InvalidDefinitionException
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:583)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1249)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1098)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312)
at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$83/517355658.getObject(Unknown Source)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:205)
at org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:228)
at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addAsRegistrationBean(ServletContextInitializerBeans.java:182)
at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addAsRegistrationBean(ServletContextInitializerBeans.java:177)
at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addAdaptableBeans(ServletContextInitializerBeans.java:159)
at org.springframework.boot.web.servlet.ServletContextInitializerBeans.<init>(ServletContextInitializerBeans.java:80)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getServletContextInitializerBeans(ServletWebServerApplicationContext.java:232)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize(ServletWebServerApplicationContext.java:219)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext$$Lambda$126/1009916891.onStartup(Unknown Source)
at org.springframework.boot.web.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:54)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5196)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.filter.OrderedHttpPutFormContentFilter]: Factory method 'httpPutFormContentFilter' threw exception; nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/exc/InvalidDefinitionException
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:186)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:575)
... 26 common frames omitted
Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/exc/InvalidDefinitionException
at org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter.<init>(AllEncompassingFormHttpMessageConverter.java:67)
at org.springframework.web.filter.HttpPutFormContentFilter.<init>(HttpPutFormContentFilter.java:63)
at org.springframework.boot.web.servlet.filter.OrderedHttpPutFormContentFilter.<init>(OrderedHttpPutFormContentFilter.java:29)
at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration.httpPutFormContentFilter(WebMvcAutoConfiguration.java:161)
at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$$EnhancerBySpringCGLIB$$f9ae12ce.CGLIB$httpPutFormContentFilter$1(<generated>)
at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$$EnhancerBySpringCGLIB$$f9ae12ce$$FastClassBySpringCGLIB$$60a40e61.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:361)
at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$$EnhancerBySpringCGLIB$$f9ae12ce.httpPutFormContentFilter(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:155)
... 27 common frames omitted
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.exc.InvalidDefinitionException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 41 common frames omitted
Gradle file
I was able to recreate the conditions of this situation with this Gradle build file.
buildscript {
ext {
kotlin_version = '1.1.51'
spring_boot_version = '2.0.0.M5'
junit_version = '5.0.1'
jackson_version = '2.7.9' // has to match Moneydance included Jackson version
}
repositories {
mavenCentral()
jcenter()
maven { url 'https://repo.spring.io/libs-milestone' } // remove when using a stable version of Spring Boot 2.x
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.1'
classpath "org.springframework.boot:spring-boot-gradle-plugin:$spring_boot_version"
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'idea'
apply plugin: 'org.junit.platform.gradle.plugin'
// apply plugin: 'org.springframework.boot' // causes problems with Spring Boot 2. Unable to compile sub-projects.
apply plugin: 'io.spring.dependency-management'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
repositories {
mavenCentral()
jcenter()
maven { url 'https://repo.spring.io/libs-milestone' }
}
dependencies {
//
// PRODUCTION
//
// Kotlin and language extensions
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
// Spring
compile("org.springframework.boot:spring-boot-starter-web:$spring_boot_version") {
// Totally excluding Jackson (version conflict between version included in Moneydance and the one used in SpringBoot
exclude group: 'com.fasterxml.jackson.core'
exclude group: 'com.fasterxml.jackson.datatype'
exclude group: 'com.fasterxml.jackson.module'
}
compile "com.fasterxml.jackson.module:jackson-module-kotlin:$jackson_version"
//
// TEST
//
// JUnit
testCompile("org.junit.jupiter:junit-jupiter-api:$junit_version")
testRuntime("org.junit.jupiter:junit-jupiter-engine:$junit_version")
}
compileKotlin {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
}
}
junitPlatform {
platformVersion '1.0.0'
}
}
The not-found class which causes the exception is InvalidDefinitionException
nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/exc/InvalidDefinitionException
I found out that InvalidDefinitionException class exists in Jackson since 2.9 as you can see here: InvalidDefinitionException
So I changed the jackson_version value to 2.9.2 (latest) in build.gradle and tried to run the project as you described and the project started to run with no exception.
Now to exclude Jackson you can still use this:
#SpringBootApplication(
exclude = arrayOf(JacksonAutoConfiguration::class)
)

Application startup failed java.lang.NoClassDefFoundError: org/springframework/util/StopWatch$TaskInfo

I have developed a batch processing program using Spring Boot 1.4.2, which takes a long time (about 5 hours) to execute. After about 5 hours passes since the program launches, it finishes execution with an error message below:
20:49:01.324 ERROR o.s.boot.SpringApplication - Application startup failed
java.lang.NoClassDefFoundError: org/springframework/util/StopWatch$TaskInfo
at org.springframework.util.StopWatch.stop(StopWatch.java:146)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:318)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175)
at com.example.Main.main(Main.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:58)
Caused by: java.lang.ClassNotFoundException: org.springframework.util.StopWatch$TaskInfo
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 13 common frames omitted
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:58)
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/SpringBootExceptionHandler
at org.springframework.boot.SpringApplication.getSpringBootExceptionHandler(SpringApplication.java:903)
at org.springframework.boot.SpringApplication.registerLoggedException(SpringApplication.java:850)
at org.springframework.boot.SpringApplication.reportFailure(SpringApplication.java:840)
at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:816)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:326)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175)
at jp.co.cyberagent.leeds.article_batches.ArticleBatchesApplication.main(ArticleBatchesApplication.java:25)
... 8 more
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringBootExceptionHandler
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 16 more
It seems that I am missing some dependencies on Spring Framework, but I don't know what I really need.
Here's my build.gradle.
buildscript {
ext {
springBootVersion = '1.4.2.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'article-batches'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
maven {
url "https://maven.ca-tools.org/content/groups/public/"
}
}
dependencies {
compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.1.1')
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.1.7'
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.40'
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.2'
compile group: 'org.mybatis', name: 'mybatis-typehandlers-jsr310', version: '1.0.1'
testCompile('org.springframework.boot:spring-boot-starter-test')
}
I solved the problem by myself. My main process was written in CommandLineRunner#run method, but it is wrong way to write main process in run method as this comment says in another question.
I followed the comment and wrote my main process like below, then the problem has gone away.
#SpringBootApplication
public class Main {
public static void main(String[] args) {
final ConfigurableApplicationContext context = SpringApplication.run(Main.class, args);
final AppBean app = context.getBean(AppBean.class);
app.run(args);
}
}

Categories

Resources