java - Spring Boot default test throws an IllegalStateException -
i starting play spring boot , have problems fresh new installation.
i have created initial project using http://start.spring.io .. here build.gradle:
buildscript { ext { springbootversion = '1.2.5.release' } repositories { mavencentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springbootversion}") classpath("io.spring.gradle:dependency-management-plugin:0.5.2.release") } } apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'idea' apply plugin: 'spring-boot' apply plugin: 'io.spring.dependency-management' jar { basename = 'springboot-demo1' version = '0.0.1-snapshot' } sourcecompatibility = 1.8 targetcompatibility = 1.8 repositories { mavencentral() } dependencies { compile("org.springframework.boot:spring-boot-starter-jdbc") runtime("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' } } task wrapper(type: wrapper) { gradleversion = '2.3' }
when execute in command line:
gradlew clean build
build fails. here output:
d:\springboot-demo1>gradlew clean build :clean :compilejava :processresources :classes :jar :findmainclass :startscripts :disttar :distzip :bootrepackage :assemble :compiletestjava :processtestresources up-to-date :testclasses :test info.gandraweb.faker.apns.javaapnsfakerapplicationtests > contextloads failed java.lang.illegalstateexception caused by: org.springframework.beans.factory.beancreationexception caused by: org.springframework.beans.factory.beancreationexception caused by: org.springframework.beans.factory.beancreationexception caused by: org.springframework.beans.beaninstantiationexception caused by: org.springframework.beans.factory.beancreationexception 1 test completed, 1 failed :test failed failure: build failed exception. * went wrong: execution failed task ':test'. > there failing tests. see report at: file:///d:/springboot-demo1/build/reports/tests/index.html * try: run --stacktrace option stack trace. run --info or --debug option more log output. build failed total time: 17.572 secs
test failed. here test class code fails:
package info.gandraweb.faker.apns; import org.junit.test; import org.junit.runner.runwith; import org.springframework.boot.test.springapplicationconfiguration; import static org.junit.assert.*; import org.springframework.test.context.junit4.springjunit4classrunner; @runwith(springjunit4classrunner.class) @springapplicationconfiguration(classes = javaapnsfakerapplication.class) public class javaapnsfakerapplicationtests { @test public void contextloads() { asserttrue(true); } }
this fresh new installation of spring boot , fails immediately. have make build passes , test execute without errors?
p.s.
here stacktrace error build\reports\tests\index.html:
java.lang.illegalstateexception: failed load applicationcontext @ org.springframework.test.context.defaultcacheawarecontextloaderdelegate.loadcontext(defaultcacheawarecontextloaderdelegate.java:94) @ org.springframework.test.context.defaulttestcontext.getapplicationcontext(defaulttestcontext.java:72) @ org.springframework.test.context.support.dependencyinjectiontestexecutionlistener.injectdependencies(dependencyinjectiontestexecutionlistener.java:117) @ org.springframework.test.context.support.dependencyinjectiontestexecutionlistener.preparetestinstance(dependencyinjectiontestexecutionlistener.java:83) @ org.springframework.test.context.testcontextmanager.preparetestinstance(testcontextmanager.java:212) @ org.springframework.test.context.junit4.springjunit4classrunner.createtest(springjunit4classrunner.java:200) @ org.springframework.test.context.junit4.springjunit4classrunner$1.runreflectivecall(springjunit4classrunner.java:259) @ org.junit.internal.runners.model.reflectivecallable.run(reflectivecallable.java:12) @ org.springframework.test.context.junit4.springjunit4classrunner.methodblock(springjunit4classrunner.java:261) @ org.springframework.test.context.junit4.springjunit4classrunner.runchild(springjunit4classrunner.java:219) @ org.springframework.test.context.junit4.springjunit4classrunner.runchild(springjunit4classrunner.java:83) @ org.junit.runners.parentrunner$3.run(parentrunner.java:290) @ org.junit.runners.parentrunner$1.schedule(parentrunner.java:71) @ org.junit.runners.parentrunner.runchildren(parentrunner.java:288) @ org.junit.runners.parentrunner.access$000(parentrunner.java:58) @ org.junit.runners.parentrunner$2.evaluate(parentrunner.java:268) @ org.springframework.test.context.junit4.statements.runbeforetestclasscallbacks.evaluate(runbeforetestclasscallbacks.java:61) @ org.springframework.test.context.junit4.statements.runaftertestclasscallbacks.evaluate(runaftertestclasscallbacks.java:68) @ org.junit.runners.parentrunner.run(parentrunner.java:363) @ org.springframework.test.context.junit4.springjunit4classrunner.run(springjunit4classrunner.java:163) @ org.gradle.api.internal.tasks.testing.junit.junittestclassexecuter.runtestclass(junittestclassexecuter.java:86) @ org.gradle.api.internal.tasks.testing.junit.junittestclassexecuter.execute(junittestclassexecuter.java:49) @ org.gradle.api.internal.tasks.testing.junit.junittestclassprocessor.processtestclass(junittestclassprocessor.java:64) @ org.gradle.api.internal.tasks.testing.suitetestclassprocessor.processtestclass(suitetestclassprocessor.java:50) @ 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:483) @ org.gradle.messaging.dispatch.reflectiondispatch.dispatch(reflectiondispatch.java:35) @ org.gradle.messaging.dispatch.reflectiondispatch.dispatch(reflectiondispatch.java:24) @ org.gradle.messaging.dispatch.contextclassloaderdispatch.dispatch(contextclassloaderdispatch.java:32) @ org.gradle.messaging.dispatch.proxydispatchadapter$dispatchinginvocationhandler.invoke(proxydispatchadapter.java:93) @ com.sun.proxy.$proxy2.processtestclass(unknown source) @ org.gradle.api.internal.tasks.testing.worker.testworker.processtestclass(testworker.java:106) @ 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:483) @ org.gradle.messaging.dispatch.reflectiondispatch.dispatch(reflectiondispatch.java:35) @ org.gradle.messaging.dispatch.reflectiondispatch.dispatch(reflectiondispatch.java:24) @ org.gradle.messaging.remote.internal.hub.messagehub$handler.run(messagehub.java:360) @ org.gradle.internal.concurrent.defaultexecutorfactory$stoppableexecutorimpl$1.run(defaultexecutorfactory.java:64) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617) @ java.lang.thread.run(thread.java:745) caused by: org.springframework.beans.factory.beancreationexception: error creating bean name 'org.springframework.boot.autoconfigure.jdbc.datasourceautoconfiguration$jdbctemplateconfiguration': injection of autowired dependencies failed; nested exception org.springframework.beans.factory.beancreationexception: not autowire field: private javax.sql.datasource org.springframework.boot.autoconfigure.jdbc.datasourceautoconfiguration$jdbctemplateconfiguration.datasource; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'datasource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/datasourceautoconfiguration$nonembeddedconfiguration.class]: bean instantiation via factory method failed; nested exception org.springframework.beans.beaninstantiationexception: failed instantiate [javax.sql.datasource]: factory method 'datasource' threw exception; nested exception org.springframework.beans.factory.beancreationexception: cannot determine embedded database driver class database type none. if want embedded database please put supported 1 on classpath. @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor.postprocesspropertyvalues(autowiredannotationbeanpostprocessor.java:334) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.populatebean(abstractautowirecapablebeanfactory.java:1210) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:537) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:476) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:303) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:230) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:299) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:194) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:755) @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:757) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:480) @ org.springframework.boot.springapplication.refresh(springapplication.java:686) @ org.springframework.boot.springapplication.run(springapplication.java:320) @ org.springframework.boot.test.springapplicationcontextloader.loadcontext(springapplicationcontextloader.java:103) @ org.springframework.test.context.defaultcacheawarecontextloaderdelegate.loadcontextinternal(defaultcacheawarecontextloaderdelegate.java:68) @ org.springframework.test.context.defaultcacheawarecontextloaderdelegate.loadcontext(defaultcacheawarecontextloaderdelegate.java:86) ... 44 more caused by: org.springframework.beans.factory.beancreationexception: not autowire field: private javax.sql.datasource org.springframework.boot.autoconfigure.jdbc.datasourceautoconfiguration$jdbctemplateconfiguration.datasource; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'datasource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/datasourceautoconfiguration$nonembeddedconfiguration.class]: bean instantiation via factory method failed; nested exception org.springframework.beans.beaninstantiationexception: failed instantiate [javax.sql.datasource]: factory method 'datasource' threw exception; nested exception org.springframework.beans.factory.beancreationexception: cannot determine embedded database driver class database type none. if want embedded database please put supported 1 on classpath. @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor$autowiredfieldelement.inject(autowiredannotationbeanpostprocessor.java:561) @ org.springframework.beans.factory.annotation.injectionmetadata.inject(injectionmetadata.java:88) @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor.postprocesspropertyvalues(autowiredannotationbeanpostprocessor.java:331) ... 59 more caused by: org.springframework.beans.factory.beancreationexception: error creating bean name 'datasource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/datasourceautoconfiguration$nonembeddedconfiguration.class]: bean instantiation via factory method failed; nested exception org.springframework.beans.beaninstantiationexception: failed instantiate [javax.sql.datasource]: factory method 'datasource' threw exception; nested exception org.springframework.beans.factory.beancreationexception: cannot determine embedded database driver class database type none. if want embedded database please put supported 1 on classpath. @ org.springframework.beans.factory.support.constructorresolver.instantiateusingfactorymethod(constructorresolver.java:599) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.instantiateusingfactorymethod(abstractautowirecapablebeanfactory.java:1119) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbeaninstance(abstractautowirecapablebeanfactory.java:1014) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:504) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:476) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:303) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:230) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:299) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:194) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.findautowirecandidates(defaultlistablebeanfactory.java:1120) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.doresolvedependency(defaultlistablebeanfactory.java:1044) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.resolvedependency(defaultlistablebeanfactory.java:942) @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor$autowiredfieldelement.inject(autowiredannotationbeanpostprocessor.java:533) ... 61 more caused by: org.springframework.beans.beaninstantiationexception: failed instantiate [javax.sql.datasource]: factory method 'datasource' threw exception; nested exception org.springframework.beans.factory.beancreationexception: cannot determine embedded database driver class database type none. if want embedded database please put supported 1 on classpath. @ org.springframework.beans.factory.support.simpleinstantiationstrategy.instantiate(simpleinstantiationstrategy.java:189) @ org.springframework.beans.factory.support.constructorresolver.instantiateusingfactorymethod(constructorresolver.java:588) ... 73 more caused by: org.springframework.beans.factory.beancreationexception: cannot determine embedded database driver class database type none. if want embedded database please put supported 1 on classpath. @ org.springframework.boot.autoconfigure.jdbc.datasourceproperties.getdriverclassname(datasourceproperties.java:137) @ org.springframework.boot.autoconfigure.jdbc.datasourceautoconfiguration$nonembeddedconfiguration.datasource(datasourceautoconfiguration.java:117) @ 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:483) @ org.springframework.beans.factory.support.simpleinstantiationstrategy.instantiate(simpleinstantiationstrategy.java:162) ... 74 more
make sure have connection properties in application.properties
for eg.
spring.datasource.url=jdbc:mysql://localhost/database spring.datasource.username=username spring.datasource.password=password spring.datasource.driver-class-name=com.mysql.jdbc.driver
Comments
Post a Comment