首页  |  知识库  |  资源下载  |  在线工具  |  A-Z  •  JAR  •  名词查         

调试sharding-jdbc报"NoClassDefFoundError: org/hamcrest/SelfDescribing..BeanCreationException/NoSuchMethodError/ClassNotFoundException"等异常无法正常执行junit@Test方法

标签:sharding-jdbc实例异常,NoClassDefFoundError,BeanCreationException,NoSuchMethodError,ClassNotFoundException,junit版本     发布时间:2019-05-27   

一、前言

调试sharding-jdbc项目junit代码报“java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing..Caused by: java.lang.ClassNotFoundException: org.hamcrest.c”、“java.lang.IllegalStateException: Failed to load ApplicationContext..Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with..Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException”、“org.springframework.beans.factory.NoSuchBeanDefinitionException:  Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}..”、“java.lang.NoSuchMethodError: org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runLeaf(Lorg/junit/runners/model/Statement;Lorg/junit/runner/Description;Lorg/junit/runner/notification/RunNotifier;)V..”、“    Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletContext..”等各种异常,导致无法正常运行junit的@Test 方法(只能运行@BeforeClass @AfterClass ) ,日志详情如下>>

 java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing@b@	at java.lang.ClassLoader.defineClass1(Native Method)@b@	at java.lang.ClassLoader.defineClass(ClassLoader.java:800)@b@	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)@b@	at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)@b@	at java.net.URLClassLoader.access$100(URLClassLoader.java:71)@b@	at java.net.URLClassLoader$1.run(URLClassLoader.java:361)@b@	at java.net.URLClassLoader$1.run(URLClassLoader.java:355)@b@	at java.security.AccessController.doPrivileged(Native Method)@b@	at java.net.URLClassLoader.findClass(URLClassLoader.java:354)@b@	at java.lang.ClassLoader.loadClass(ClassLoader.java:425)@b@	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)@b@	at java.lang.ClassLoader.loadClass(ClassLoader.java:358)@b@	at java.lang.Class.getDeclaredConstructors0(Native Method)@b@	at java.lang.Class.privateGetDeclaredConstructors(Class.java:2595)@b@	at java.lang.Class.getConstructor0(Class.java:2895)@b@	at java.lang.Class.getConstructor(Class.java:1731)@b@	at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)@b@	at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)@b@	at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)@b@	at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)@b@	at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)@b@	at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)@b@	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:32)@b@	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)@b@	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:41)@b@	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:31)@b@	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)@b@	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)@b@	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)@b@	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)@b@Caused by: java.lang.ClassNotFoundException: org.hamcrest.c@b@	at java.net.URLClassLoader$1.run(URLClassLoader.java:366)@b@	at java.net.URLClassLoader$1.run(URLClassLoader.java:355)@b@	at java.security.AccessController.doPrivileged(Native Method)@b@	at java.net.URLClassLoader.findClass(URLClassLoader.java:354)@b@	at java.lang.ClassLoader.loadClass(ClassLoader.java:425)@b@	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)@b@	at java.lang.ClassLoader.loadClass(ClassLoader.java:358)@b@	... 30 more
java.lang.IllegalStateException: Failed to load ApplicationContext@b@	at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:94)@b@	at org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:72)@b@	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)@b@	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)@b@	at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:212)@b@	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:200)@b@	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:252)@b@	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)@b@	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:254)@b@	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:217)@b@	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:83)@b@	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)@b@	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)@b@	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)@b@	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)@b@	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)@b@	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)@b@	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)@b@	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)@b@	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:68)@b@	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)@b@	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:163)@b@	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)@b@	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)@b@	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)@b@	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)@b@	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)@b@	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)@b@Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'studentServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'studentMapper' defined in file [C:\xwood_net\project\xwood-project\sharding-jdbc-mybatis\target\classes\com\lyz\sharding\mapper\StudentMapper.class]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in URL [file:/C:/xwood_net/project/xwood-project/sharding-jdbc-mybatis/target/classes/config/spring/spring-sharding.xml]: Cannot resolve reference to bean 'shardingDataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'shardingDataSource' defined in URL [file:/C:/xwood_net/project/xwood-project/sharding-jdbc-mybatis/target/classes/config/spring/spring-sharding.xml]: Cannot resolve reference to bean 'shardingRule' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'shardingRule' defined in URL [file:/C:/xwood_net/project/xwood-project/sharding-jdbc-mybatis/target/classes/config/spring/spring-sharding.xml]: Cannot resolve reference to bean 'dataSourceRule' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceRule' defined in URL [file:/C:/xwood_net/project/xwood-project/sharding-jdbc-mybatis/target/classes/config/spring/spring-sharding.xml]: Cannot resolve reference to bean 'sharding_0' while setting constructor argument with key [TypedStringValue: value [sharding_0], target type [null]]; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'sharding_0' is defined@b@	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:308)@b@	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1202)@b@	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)@b@	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)@b@	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)@b@	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)@b@	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)@b@	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)@b@	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:762)@b@	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)@b@	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)@b@	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:125)@b@	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)@b@	at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:109)@b@	at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:261)@b@	at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:68)@b@	at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:86)@b@	... 27 more
	org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.lyz.sharding.test.ShardingJdbcMybatisTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public com.lyz.sharding.service.UserService com.lyz.sharding.test.ShardingJdbcMybatisTest.userService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.lyz.sharding.service.UserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}@b@	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)@b@	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1202)@b@	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:385)@b@	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:118)@b@	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)@b@	at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:212)@b@	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:200)@b@	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:252)@b@	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)@b@	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:254)@b@	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:217)@b@	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:83)@b@	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)@b@	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)@b@	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)@b@	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)@b@	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)@b@	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)@b@	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)@b@	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)@b@	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:68)@b@	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)@b@	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:163)@b@	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)@b@	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)@b@	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)@b@	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)@b@	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)@b@	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)@b@Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: public com.lyz.sharding.service.UserService com.lyz.sharding.test.ShardingJdbcMybatisTest.userService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.lyz.sharding.service.UserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}@b@	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)@b@	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)@b@	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)@b@	... 28 more@b@Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.lyz.sharding.service.UserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}@b@	at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1308)@b@	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1054)@b@	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:949)@b@	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)@b@	... 30 more
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.lyz.sharding.test.ShardingJdbcMybatisTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public com.lyz.sharding.service.UserService com.lyz.sharding.test.ShardingJdbcMybatisTest.userService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.lyz.sharding.service.UserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}@b@	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)@b@	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1202)@b@	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:385)@b@	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:118)@b@	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)@b@	at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:212)@b@	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:200)@b@	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:252)@b@	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)@b@	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:254)@b@	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:217)@b@	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:83)@b@	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)@b@	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)@b@	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)@b@	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)@b@	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)@b@	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)@b@	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)@b@	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)@b@	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:68)@b@	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)@b@	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:163)@b@	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)@b@	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)@b@	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)@b@	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)@b@	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)@b@	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)@b@Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: public com.lyz.sharding.service.UserService com.lyz.sharding.test.ShardingJdbcMybatisTest.userService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.lyz.sharding.service.UserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}@b@	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)@b@	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)@b@	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)@b@	... 28 more@b@Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.lyz.sharding.service.UserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}@b@	at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1308)@b@	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1054)@b@	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:949)@b@	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)@b@	... 30 more @b@@b@org.springframework.beans.factory.NoSuchBeanDefinitionException:  Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
 java.lang.NoSuchMethodError: org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runLeaf(Lorg/junit/runners/model/Statement;Lorg/junit/runner/Description;Lorg/junit/runner/notification/RunNotifier;)V@b@	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:217)@b@	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:83)@b@	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)@b@	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)@b@	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)@b@	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)@b@	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)@b@	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)@b@	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)@b@	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)@b@	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:68)@b@	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)@b@	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:163)@b@	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)@b@	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)@b@	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)@b@	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)@b@	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)@b@	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

二、解决方法

1. 如下图,因项目引入eclipse自带Junit4版本,且版本只有junit4.8.1的版本,与项目spring4.1.4的版本不能兼容

调试sharding-jdbc报"NoClassDefFoundError: org/hamcrest/SelfDescribing..BeanCreationException/NoSuchMethodError/ClassNotFoundException"等异常无法正常执行junit@Test方法

2. 如下图引入junit-4.12.jar高版本即可解决问题了

调试sharding-jdbc报"NoClassDefFoundError: org/hamcrest/SelfDescribing..BeanCreationException/NoSuchMethodError/ClassNotFoundException"等异常无法正常执行junit@Test方法