Getting BeanCreationException when I try to run spring boot web application?

random_user

I created a web project in intelliJ. then I created Application.kt and HomeController.kt . Now I am trying to run this web application using ./gradlew :bootRun , But it's throwing following exception . I don't know , what am I doing wrong? can anyone figure it out? what is the actual problem here . Thanks in Advance

stack trace

2018-03-07 17:57:53.868  INFO 26063 --- [           main] ApplicationKt                            : Starting ApplicationKt on xyz-x541uj with PID 26063 (/home/xyz/Desktop/root/intelliJ/WebPro/build/classes/kotlin/main started by xyz in /home/xyz/Desktop/root/intelliJ/WebPro)
2018-03-07 17:57:53.878  INFO 26063 --- [           main] ApplicationKt                            : No active profile set, falling back to default profiles: default
2018-03-07 17:57:53.971  INFO 26063 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@667a738: startup date [Wed Mar 07 17:57:53 IST 2018]; root of context hierarchy
2018-03-07 17:57:54.123  WARN 26063 --- [kground-preinit] o.s.h.c.j.Jackson2ObjectMapperBuilder    : For Jackson Kotlin classes support please add "com.fasterxml.jackson.module:jackson-module-kotlin" to the classpath
2018-03-07 17:57:55.405  INFO 26063 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2018-03-07 17:57:55.431  INFO 26063 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-03-07 17:57:55.432  INFO 26063 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.28
2018-03-07 17:57:55.442  INFO 26063 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]
2018-03-07 17:57:55.525  INFO 26063 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-03-07 17:57:55.525  INFO 26063 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1557 ms
2018-03-07 17:57:55.676  INFO 26063 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2018-03-07 17:57:55.680  INFO 26063 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-03-07 17:57:55.681  INFO 26063 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-03-07 17:57:55.681  INFO 26063 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-03-07 17:57:55.681  INFO 26063 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2018-03-07 17:57:55.722  WARN 26063 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'homeController' defined in file [/home/ankush/Desktop/root/intelliJ/WebPro/build/classes/kotlin/main/com/webpro/controller/HomeController.class]: Unexpected exception during bean creation; nested exception is java.lang.NoClassDefFoundError: kotlin/reflect/full/KClasses
2018-03-07 17:57:55.724  INFO 26063 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2018-03-07 17:57:55.737  INFO 26063 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-03-07 17:57:55.743 ERROR 26063 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'homeController' defined in file [/home/ankush/Desktop/root/intelliJ/WebPro/build/classes/kotlin/main/com/webpro/controller/HomeController.class]: Unexpected exception during bean creation; nested exception is java.lang.NoClassDefFoundError: kotlin/reflect/full/KClasses
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:518) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:388) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1234) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
        at ApplicationKt.main(Application.kt:18) [main/:na]
Caused by: java.lang.NoClassDefFoundError: kotlin/reflect/full/KClasses
        at org.springframework.beans.BeanUtils$KotlinDelegate.findPrimaryConstructor(BeanUtils.java:727) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
        at org.springframework.beans.BeanUtils.findPrimaryConstructor(BeanUtils.java:200) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:286) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1198) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1123) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
        ... 14 common frames omitted
Caused by: java.lang.ClassNotFoundException: kotlin.reflect.full.KClasses
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_161]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_161]
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338) ~[na:1.8.0_161]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_161]
        ... 21 common frames omitted



FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':bootRun'.
> Process 'command '/usr/lib/jvm/java-8-oracle/bin/java'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED in 3s
2 actionable tasks: 1 executed, 1 up-to-date

build.gradle

       buildscript {
    ext.kotlin_version = '1.2.30'

    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.0.RELEASE")

    }
}

        group 'com.xxx.web'
version '1.0-SNAPSHOT'

apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'
apply plugin: 'io.spring.dependency-management'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    compile("org.springframework.boot:spring-boot-starter-thymeleaf")
    compile("org.springframework.boot:spring-boot-starter-web")

    testCompile group: 'junit', name: 'junit', version: '4.12'
}

compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

Application.kt

       import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.context.annotation.ComponentScan



@ComponentScan("com.webpro")
@SpringBootApplication
open class Application

fun main(args:Array<String>)
{
    SpringApplication.run(Application::class.java,*args)
}

HomeController.kt

    package com.webpro.controller

import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController



@RestController
class HomeController
{
    @GetMapping("/")
    fun greeting() : String
    {
        return "Hello World !"
    }
}
Dave Leeds

Something in the code is trying to use Kotlin reflection. In order to cut down the size of the runtime library, Kotlin reflection features are provided separately from the standard library, as a separate JAR.

To add this dependency to your build, update your build.gradle file by putting this line inside the dependencies block:

compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why I am getting error not found error in Spring boot application

How can I run a Spring Boot application on port 80

BeanCreationException getting error while runing spring boot batch application

Application run failed in Spring Boot

Why am I getting a Hibernate LazyInitializationException in this Spring MVC web application when the data displays correctly?

I am getting Cannot get a connection, pool error Timeout waiting for idle object, When I try to create more than 250 threads in my web application

I keep getting this @bean error when trying to run my spring boot app with dynamodb and graphql

A NullPointerException is caught when I try to add a new client in a CRUD Spring boot Application

Spring Boot Application Throwing Startup Failed Error When Trying to Run

Configuration Spring-BOOT when i run i resolve exception

My spring boot application is working perfectly when started in STS but if I try with jar, this method kills it?

Spring Boot Application run failed

Can I run long tasks in a Spring Boot application?

TypeError when I try to run mt Node.js application

Unable to run web application using spring boot

Exception occurs when I try to pass a custom error to client in spring boot application

How to run a Spring Boot maven project in VSCode and how to config the base url of a spring boot web application

BeanCreationException,Spring boot

Getting "invalid NEW or OLD specification" message when I try to run this

Error when launching a web application on Spring-Boot

org.springframework.beans.factory.BeanCreationException in Spring boot application

tests for spring boot application are not run

Using Spring Boot Thymeleaf by do not run as a web application

Spring AOP using @around throws org.springframework.beans.factory.BeanCreationException when I start the application

Run spring boot application on server

Transaction is not committed when spring boot application is run from java -jar

Getting errors when i try to run dot net watch run on my Blazor project on .net5

How to fix 'Error Creating Bean' (BeanCreationException) in Maven Spring Boot Application?

Forbidden 403 Error in spring boot when i try to access the web app (index.html) or reactjs app