java - ERROR 7405 --- [ main] o.s.boot.SpringApplication : Application startup failed -
i using gradle 2.9 , springbootversion = '1.3.1.release' build successful jar deployment not successful. these logs:
2016-02-05 20:44:13.905 warn 7405 --- [ main] ationconfigembeddedwebapplicationcontext : exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.beancreationexception: error creating bean name 'entitymanagerfactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/hibernatejpaautoconfiguration.class]: invocation of init method failed; nested exception java.lang.noclassdeffounderror: org/hibernate/boot/registry/classloading/internal/classloaderserviceimpl$work 2016-02-05 20:44:13.916 info 7405 --- [ main] o.apache.catalina.core.standardservice : stopping service tomcat 2016-02-05 20:44:13.942 error 7405 --- [ main] o.s.boot.springapplication : application startup failed org.springframework.beans.factory.beancreationexception: error creating bean name 'entitymanagerfactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/hibernatejpaautoconfiguration.class]: invocation of init method failed; nested exception java.lang.noclassdeffounderror: org/hibernate/boot/registry/classloading/internal/classloaderserviceimpl$work @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1578) ~[spring-beans-4.2.4.release.jar!/:4.2.4.release] @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:545) ~[spring-beans-4.2.4.release.jar!/:4.2.4.release] @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:482) ~[spring-beans-4.2.4.release.jar!/:4.2.4.release] @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:306) ~[spring-beans-4.2.4.release.jar!/:4.2.4.release] @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:230) ~[spring-beans-4.2.4.release.jar!/:4.2.4.release] @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:302) ~[spring-beans-4.2.4.release.jar!/:4.2.4.release] @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:197) ~[spring-beans-4.2.4.release.jar!/:4.2.4.release] @ org.springframework.context.support.abstractapplicationcontext.getbean(abstractapplicationcontext.java:1054) ~[spring-context-4.2.4.release.jar!/:4.2.4.release] @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:829) ~[spring-context-4.2.4.release.jar!/:4.2.4.release] @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:538) ~[spring-context-4.2.4.release.jar!/:4.2.4.release] @ org.springframework.boot.context.embedded.embeddedwebapplicationcontext.refresh(embeddedwebapplicationcontext.java:118) ~[spring-boot-1.3.1.release.jar!/:1.3.1.release] @ org.springframework.boot.springapplication.refresh(springapplication.java:764) [spring-boot-1.3.1.release.jar!/:1.3.1.release] @ org.springframework.boot.springapplication.dorun(springapplication.java:357) [spring-boot-1.3.1.release.jar!/:1.3.1.release] @ org.springframework.boot.springapplication.run(springapplication.java:305) [spring-boot-1.3.1.release.jar!/:1.3.1.release] @ org.springframework.boot.springapplication.run(springapplication.java:1124) [spring-boot-1.3.1.release.jar!/:1.3.1.release] @ org.springframework.boot.springapplication.run(springapplication.java:1113) [spring-boot-1.3.1.release.jar!/:1.3.1.release] @ com.opensecret.opensecretapplication.main(opensecretapplication.java:10) [open-secret-0.0.1-snapshot.jar!/:na] @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) ~[na:1.8.0_65] @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) ~[na:1.8.0_65] @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) ~[na:1.8.0_65] @ java.lang.reflect.method.invoke(method.java:497) ~[na:1.8.0_65] @ org.springframework.boot.loader.mainmethodrunner.run(mainmethodrunner.java:53) [open-secret-0.0.1-snapshot.jar!/:na] @ java.lang.thread.run(thread.java:745) [na:1.8.0_65] caused by: java.lang.noclassdeffounderror: org/hibernate/boot/registry/classloading/internal/classloaderserviceimpl$work @ org.springframework.orm.jpa.vendor.springhibernatejpapersistenceprovider.createcontainerentitymanagerfactory(springhibernatejpapersistenceprovider.java:54) ~[spring-orm-4.2.4.release.jar!/:4.2.4.release] @ org.springframework.orm.jpa.localcontainerentitymanagerfactorybean.createnativeentitymanagerfactory(localcontainerentitymanagerfactorybean.java:343) ~[spring-orm-4.2.4.release.jar!/:4.2.4.release] @ org.springframework.orm.jpa.abstractentitymanagerfactorybean.afterpropertiesset(abstractentitymanagerfactorybean.java:318) ~[spring-orm-4.2.4.release.jar!/:4.2.4.release] @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.invokeinitmethods(abstractautowirecapablebeanfactory.java:1637) ~[spring-beans-4.2.4.release.jar!/:4.2.4.release] @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1574) ~[spring-beans-4.2.4.release.jar!/:4.2.4.release] ... 22 common frames omitted caused by: java.lang.classnotfoundexception: org.hibernate.boot.registry.classloading.internal.classloaderserviceimpl$work @ java.net.urlclassloader.findclass(urlclassloader.java:381) ~[na:1.8.0_65] @ java.lang.classloader.loadclass(classloader.java:424) ~[na:1.8.0_65] @ org.springframework.boot.loader.launchedurlclassloader.doloadclass(launchedurlclassloader.java:178) ~[open-secret-0.0.1-snapshot.jar!/:na] @ org.springframework.boot.loader.launchedurlclassloader.loadclass(launchedurlclassloader.java:142) ~[open-secret-0.0.1-snapshot.jar!/:na] @ java.lang.classloader.loadclass(classloader.java:357) ~[na:1.8.0_65] ... 27 common frames omitted 2016-02-05 20:44:13.958 warn 7405 --- [ main] o.s.boot.springapplication : error handling failed (error creating bean name 'delegatingapplicationlistener' defined in class path resource [org/springframework/security/config/annotation/web/configuration/websecurityconfiguration.class]: beanpostprocessor before instantiation of bean failed; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'org.springframework.transaction.annotation.proxytransactionmanagementconfiguration': initialization of bean failed; nested exception org.springframework.beans.factory.nosuchbeandefinitionexception: no bean named 'org.springframework.context.annotation.configurationclasspostprocessor.importregistry' defined) java.lang.reflect.invocationtargetexception @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:497) @ org.springframework.boot.loader.mainmethodrunner.run(mainmethodrunner.java:53) @ java.lang.thread.run(thread.java:745) caused by: org.springframework.beans.factory.beancreationexception: error creating bean name 'entitymanagerfactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/hibernatejpaautoconfiguration.class]: invocation of init method failed; nested exception java.lang.noclassdeffounderror: org/hibernate/boot/registry/classloading/internal/classloaderserviceimpl$work @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1578) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:545) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:482) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:306) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:230) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:302) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:197) @ org.springframework.context.support.abstractapplicationcontext.getbean(abstractapplicationcontext.java:1054) @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:829) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:538) @ org.springframework.boot.context.embedded.embeddedwebapplicationcontext.refresh(embeddedwebapplicationcontext.java:118) @ org.springframework.boot.springapplication.refresh(springapplication.java:764) @ org.springframework.boot.springapplication.dorun(springapplication.java:357) @ org.springframework.boot.springapplication.run(springapplication.java:305) @ org.springframework.boot.springapplication.run(springapplication.java:1124) @ org.springframework.boot.springapplication.run(springapplication.java:1113) @ com.opensecret.opensecretapplication.main(opensecretapplication.java:10) ... 6 more caused by: java.lang.noclassdeffounderror: org/hibernate/boot/registry/classloading/internal/classloaderserviceimpl$work @ org.springframework.orm.jpa.vendor.springhibernatejpapersistenceprovider.createcontainerentitymanagerfactory(springhibernatejpapersistenceprovider.java:54) @ org.springframework.orm.jpa.localcontainerentitymanagerfactorybean.createnativeentitymanagerfactory(localcontainerentitymanagerfactorybean.java:343) @ org.springframework.orm.jpa.abstractentitymanagerfactorybean.afterpropertiesset(abstractentitymanagerfactorybean.java:318) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.invokeinitmethods(abstractautowirecapablebeanfactory.java:1637) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1574) ... 22 more caused by: java.lang.classnotfoundexception: org.hibernate.boot.registry.classloading.internal.classloaderserviceimpl$work @ java.net.urlclassloader.findclass(urlclassloader.java:381) @ java.lang.classloader.loadclass(classloader.java:424) @ org.springframework.boot.loader.launchedurlclassloader.doloadclass(launchedurlclassloader.java:178) @ org.springframework.boot.loader.launchedurlclassloader.loadclass(launchedurlclassloader.java:142) @ java.lang.classloader.loadclass(classloader.java:357) ... 27 more
this gradle file:
buildscript { ext { springbootversion = '1.3.1.release' hibernateversion = '5.0.7.final' mysqlversion = '5.1.6' junitversion = '4.12' } repositories { mavencentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springbootversion}") } } apply plugin: 'spring-boot' jar { basename = 'open-secret' version = '0.0.1-snapshot' } dependencies { compile("org.springframework.boot:spring-boot-starter-actuator:${springbootversion}") compile("org.springframework.boot:spring-boot-starter-web:${springbootversion}") compile("org.springframework.boot:spring-boot-starter-data-jpa:${springbootversion}") compile("org.springframework.boot:spring-boot-starter-security:${springbootversion}") compile("org.hibernate:hibernate-core:${hibernateversion}") compile("mysql:mysql-connector-java:${mysqlversion}") testcompile("org.springframework.boot:spring-boot-starter-test:${springbootversion}") testcompile("junit:junit:${junitversion}") testcompile("org.mockito:mockito-core:1.10.19") } 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.8' } }
this controller:
package com.opensecret.controller; import org.springframework.beans.factory.annotation.autowired; import org.springframework.web.bind.annotation.*; import com.opensecret.model.user; import com.opensecret.repository.userrepository; import java.util.list; @restcontroller @requestmapping(value="/api/user") public class usercontroller { @autowired private userrepository userrepository; @requestmapping(method = requestmethod.get) public list<user> findall() { return userrepository.findall(); } @requestmapping(method = requestmethod.post) public user add(@requestbody user user) { user model = new user(); model.setemail(user.getemail()); model.setname(user.getemail()); return userrepository.saveandflush(model); } @requestmapping(value = "/{id}", method = requestmethod.get) public user findone(@pathvariable int id) { return userrepository.findone(id); } @requestmapping(value = "/{id}", method = requestmethod.put) public user update(@pathvariable int id, @requestbody user user) { user model = userrepository.findone(id); if (model != null) { model.setname(user.getname()); model.setemail(user.getemail()); return userrepository.saveandflush(model); } return null; } @requestmapping(value = "/{id}", method = requestmethod.delete) public void delete(@pathvariable int id) { userrepository.delete(id); } } model: package com.opensecret.model; import javax.persistence.*; import javax.validation.constraints.notnull; import javax.validation.constraints.size; @entity @table(name="users") public class user { @id @generatedvalue(strategy = generationtype.auto) @column(name = "id") private int id; @notnull @size(min = 3, max = 80) @column(name = "email") private string email; @notnull @size(min = 2, max = 80) @column(name = "name") private string name; public int getid() { return id; } public string getemail() { return email; } public string getname() { return name; } public void setname(string name) { this.name = name; } public void setid(int id) { this.id = id; } public void setemail(string email) { this.email = email; } }
this security config:
package com.opensecret.config; import org.springframework.context.annotation.configuration; import org.springframework.http.httpmethod; import org.springframework.security.config.annotation.web.builders.httpsecurity; import org.springframework.security.config.annotation.web.configuration.websecurityconfigureradapter; import org.springframework.security.config.http.sessioncreationpolicy; @configuration public class securityconfig extends websecurityconfigureradapter { @override protected void configure(httpsecurity http) throws exception { http .csrf().disable() .authorizerequests() .antmatchers(httpmethod.post, "/api/**").authenticated() .antmatchers(httpmethod.put, "/api/**").authenticated() .antmatchers(httpmethod.delete, "/api/**").authenticated() .anyrequest().permitall() .and() .httpbasic().and() .sessionmanagement().sessioncreationpolicy(sessioncreationpolicy.stateless); } }
this repository:
import com.opensecret.model.user; import org.springframework.data.jpa.repository.jparepository; import org.springframework.stereotype.repository; @repository public interface userrepository extends jparepository<user,integer>{ }
this application.properties:
server.port: 9000 management.port: 9001 management.address: 127.0.0.1 spring.datasource.url= jdbc:mysql://localhost:3306/opensecret spring.datasource.driver-class-name=com.mysql.jdbc.driver spring.datasource.username=root spring.datasource.password=password spring.jpa.hibernate.ddl-auto=create-drop
and main:
package com.opensecret; import org.springframework.boot.springapplication; import org.springframework.boot.autoconfigure.springbootapplication; @springbootapplication public class opensecretapplication { public static void main(string[] args) { springapplication.run(opensecretapplication.class, args); } }
please me not able understand why it's happening...
you've got mixture of hibernate versions on classpath result of hibernateversion
being set 5.0.7.final
, spring-boot-starter-data-jpa
, hibernate-core
dependencies:
compile("org.springframework.boot:spring-boot-starter-datajpa:${springbootversion}") compile("org.hibernate:hibernate-core:${hibernateversion}")
spring-boot-starter-data-jpa
depends on hibernate-entitymanager
4.3.11.final which, in turn, depends on hibernate-core
. you've overridden version of latter you've got hibernate-entitymanager
4.3.11 mixed hibernate-core
5.0.7.final.
the simplest solution replace dependency on hibernate-core
1 on hibernate-entitymanager
dependencies this:
dependencies { compile("org.springframework.boot:spring-boot-starter-actuator:${springbootversion}") compile("org.springframework.boot:spring-boot-starter-web:${springbootversion}") compile("org.springframework.boot:spring-boot-starter-data-jpa:${springbootversion}") compile("org.springframework.boot:spring-boot-starter-security:${springbootversion}") compile("org.hibernate:hibernate-entitymanager:${hibernateversion}") compile("mysql:mysql-connector-java:${mysqlversion}") testcompile("org.springframework.boot:spring-boot-starter-test:${springbootversion}") testcompile("junit:junit:${junitversion}") testcompile("org.mockito:mockito-core:1.10.19") }
i'd recommend take things step further, though. spring boot's gradle plugin provides dependency management , several third-party libraries means don't need specify version when declare dependency. if take advantage of , remove dependencies pulled in transitively, can simplify build.gradle
this:
buildscript { repositories { mavencentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.1.release") } } apply plugin: 'spring-boot' apply plugin: 'eclipse' jar { basename = 'open-secret' version = '0.0.1-snapshot' } repositories { mavencentral() } ext['hibernate.version'] = '5.0.7.final' dependencies { compile("org.springframework.boot:spring-boot-starter-actuator") compile("org.springframework.boot:spring-boot-starter-web") compile("org.springframework.boot:spring-boot-starter-data-jpa") compile("org.springframework.boot:spring-boot-starter-security") compile("mysql:mysql-connector-java") testcompile("org.springframework.boot:spring-boot-starter-test") } 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.8' } }
note ext['hibernate.version'] = '5.0.7.final'
being used override spring boot's default hibernate version (4.3.11.final) 1 want.
Comments
Post a Comment