springtestmapper注⼊失败问题解决{@org.springframework。。。
花费了⼀下午都没有搜索到相关解决⽅案的原因,⼀是我使⽤的 UnsatisfiedDependencyException 这个⽐较上层的异常(在最前⾯)来进⾏搜索,
范围太⼴导致没有搜索到,⽽且即便是有⼈提出是包扫描的问题,但是我spring的基础太差,所以也不知道该怎么操作,
然后这次⼜印证了我之前的那篇博客,即碰到异常⼀定要到根异常,参考我之前的⽂章:;
根异常⼀般在异常⾏的末尾,这次就是搜索末尾的 {@org.springframework.beans.factory.annotation.Autowired(required=true)} ,才搜索到下⾯的这篇解决的博客的,
注:这个问题跟类名,⽅法名,idea版本没有任何关系。
注:每次使⽤springtest进⾏⾮web的测试时,都需要按照下⾯的正确⽰例来写注解,并且设置idea resources为 test resources,并且在 l 中,
把包扫描设置为⾃动配置 <context:annotation-config /> ,否则会报BeanCreationException: Error creating bean with name
<!-- 将以下内容替换 -->
<context:component-scan base-package="org.kinome">
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller"></context:exclude-filter>
</context:component-scan>
<!-- 替换为 -->
<context:annotation-config />
这⾥是包扫描出现了问题导致的,原因不明,
不过如果替换成了这个的话,项⽬启动时会有⼀些启动类出现注⼊问题,所以如果要做springtest的话,⽤替换为的包扫描⾃动配置,如果要启动项⽬的话,就换回替换之前的包扫描配置。(两个配置不⽤哪个注释掉就可以了,当做选项灵活配置)
注意:如果仅仅做springtest,不涉及web,那么就只加载 l 就可以了,否则会报错。
正确⽰例:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "l")
public class TestExample {
@Autowired
AssetsDevicetypeRefactorMapper assetsDevicetypeRefactorMapper;
@Test
public void test() {
AssetsDevicetypeRefactorExample example = new AssetsDevicetypeRefactorExample();
AssetsDevicetypeRefactorExample.Criteria criteria = ateCriteria();
<().andIscustomizeEqualTo("N");
<().andInfosysidEqualTo(1);
List<AssetsDevicetypeRefactor> assetsDevicetypeRefactors = assetsDevicetypeRefactorMapper.selectByExample(example);
for (AssetsDevicetypeRefactor adr
: assetsDevicetypeRefactors
) {
System.out.Name());
}
}
}
要想正常使⽤springtest,还需要把resources设置为 test resources
下⾯是只引⼊ l ,但是包扫描没有⽤⾃动配置,⽽是⽤的那个⾃定义的包扫描(也就是上⾯那个长的),做springtest时出现的异常
"C:\Program Files\Java\jdk1.8.0_151\" -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:7284,suspend=y,server=n -ea -lic.buffer.size=1048576 -javaagent:C:\Users\Administrator\.IntelliJIdea2018.3\system\capture Connected to the target VM, address: '127.0.0.1:7284', transport: 'socket'
[main] INFO st.context.support.DefaultTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [st.context.web.ServletTestExecution [main] INFO st.context.support.DefaultTestContextBootstrapper - Using TestExecutionListeners: [st.context.web.ServletTestExecutionListener@54c562f7, st.context.support.D [main] INFO org.springframework.l.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [l]
[main] INFO t.support.GenericApplicationContext - Refreshing t.support.GenericApplicationContext@130161f7: startup date [Wed Jan 09 14:40:41 CST 2019]; root of context hierarchy [INFO ] 2019-01-09 14:40:42,692 hange.v2.log.MLog.<clinit>(MLog.java:80)
MLog clients using log4j logging.
[INFO ] 2019-01-09 14:40:42,872 hange.v2.c3p0.C3P0Registry.banner(C3P0Registry.java:204)
Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]
[main] WARN t.support.GenericApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with [main] ERROR st.context.TestContextManager - Caught exception while allowing TestExecutionListener [st.context.support.DependencyInjectionTestExecutionListener@6dbb137d] to prepare test ins java.lang.IllegalStateException: Failed to load ApplicationContext
at st.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
at st.context.ApplicationContext(DefaultTestContext.java:83)
at st.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
at st.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
at st.context.TestContextManager.prepareTestInstance(TestContextManager.java:230)
at st.context.ateTest(SpringJUnit4ClassRunner.java:228)
at st.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287)
at org.junit.del.ReflectiveCallable.run(ReflectiveCallable.java:12)
at st.context.hodBlock(SpringJUnit4ClassRunner.java:289)
at st.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247)
at st.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at st.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at st.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at st.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at cution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at cution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at cution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'assetParser' defined in file [D:\project2\RM\target\classes\org\kinome\rm\utils\file\AssetParser.class]: Instantiation of bean failed; nested exc at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1155)
at org.springframework.beans.factory.ateBeanInstance(AbstractAutowireCapableBeanFactory.java:1099)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
at org.springframework.beans.factory.ateBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.Object(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.Singleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.Bean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
at t.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
at t.fresh(AbstractApplicationContext.java:542)
at st.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128)
at st.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
at st.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:108)
at st.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:251)
at st.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
at st.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
... 24 more
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [utils.file.AssetParser]: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:154)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:89)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1147)
... 40 more
Caused by: java.lang.NullPointerException
at e.Bean(SpringContextUtil.java:25)
at utils.file.AssetParser.<init>(AssetParser.java:33)
wInstance0(Native Method)
wInstance(NativeConstructorAccessorImpl.java:62)
wInstance(DelegatingConstructorAccessorImpl.java:45)
at wInstance(Constructor.java:423)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:142)
... 42 more
java.lang.IllegalStateException: Failed to load ApplicationContext
at st.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
at st.context.ApplicationContext(DefaultTestContext.java:83)
at st.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
at st.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
at st.context.TestContextManager.prepareTestInstance(TestContextManager.java:230)
at st.context.ateTest(SpringJUnit4ClassRunner.java:228)
at st.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287)
at org.junit.del.ReflectiveCallable.run(ReflectiveCallable.java:12)
at st.context.hodBlock(SpringJUnit4ClassRunner.java:289)
at st.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247)
at st.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at st.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at st.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at st.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at cution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at cution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at cution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'assetParser' defined in file [D:\project2\RM\target\classes\org\kinome\rm\utils\file\AssetParser.class]: Instantiation of bean failed; nested exc at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1155)
at org.springframework.beans.factory.ateBeanInstance(AbstractAutowireCapableBeanFactory.java:1099)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
at org.springframework.beans.factory.ateBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.Object(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.Singleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.Bean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
at t.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
at t.fresh(AbstractApplicationContext.java:542)
at st.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128)
at st.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
at st.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:108)
at st.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:251)
at st.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
at st.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
... 24 more
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [utils.file.AssetParser]: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:154)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:89)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1147)
... 40 more
Caused by: java.lang.NullPointerException
at e.Bean(SpringContextUtil.java:25)
at utils.file.AssetParser.<init>(AssetParser.java:33)
wInstance0(Native Method)
wInstance(NativeConstructorAccessorImpl.java:62)
wInstance(DelegatingConstructorAccessorImpl.java:45)
at wInstance(Constructor.java:423)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:142)
... 42 more
Disconnected from the target VM, address: '127.0.0.1:7284', transport: 'socket'
Process finished with exit code -1
下⾯是引⼊ applicationContext*.xml 时抛出的异常(扫描包配置为不⾃动配置):
"C:\Program Files\Java\jdk1.8.0_151\" -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:4279,suspend=y,server=n -ea -lic.
buffer.size=1048576 -javaagent:C:\Users\Administrator\.IntelliJIdea2018.3\system\capture Connected to the target VM, address: '127.0.0.1:4279', transport: 'socket'
[main] INFO st.context.support.DefaultTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [st.context.web.ServletTestExecution [main] INFO st.context.support.DefaultTestContextBootstrapper - Using TestExecutionListeners: [st.context.web.ServletTestExecutionListener@27ae2fd0, st.context.support.D
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'TestExample': Unsatisfied dependency expressed through field 'assetsDevicetypeRefactorMapper'; nested exception is org.springframework.be
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:386)
at st.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:118)
at st.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
at st.context.TestContextManager.prepareTestInstance(TestContextManager.java:230)
at st.context.ateTest(SpringJUnit4ClassRunner.java:228)
at st.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287)
at org.junit.del.ReflectiveCallable.run(ReflectiveCallable.java:12)
at st.context.hodBlock(SpringJUnit4ClassRunner.java:289)
at st.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247)
at st.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at st.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at st.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at st.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at cution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at cution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at cution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'dao.AssetsDevicetypeRefactorMapper' available: expected at least 1 bean which
qualifies as autowire candidate. Depend at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1486)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1104)
at org.springframework.beans.factory.solveDependency(DefaultListableBeanFactory.java:1066)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585)
... 35 more
[main] INFO t.support.GenericApplicationContext - Refreshing t.support.GenericApplicationContext@2ef3eef9: startup date [Wed Jan 09 15:45:26 CST 2019]; root of context hierarchy [main] ERROR st.context.TestContextManager - Caught exception while allowing TestExecutionListener [st.context.support.DependencyInjectionTestExecutionLi
stener@2f177a4b] to prepare test ins org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'TestExample': Unsatisfied dependency expressed through field 'assetsDevicetypeRefactorMapper'; nested exception is org.springframework.be at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:386)
at st.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:118)
at st.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
at st.context.TestContextManager.prepareTestInstance(TestContextManager.java:230)
at st.context.ateTest(SpringJUnit4ClassRunner.java:228)
at st.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287)
at org.junit.del.ReflectiveCallable.run(ReflectiveCallable.java:12)
at st.context.hodBlock(SpringJUnit4ClassRunner.java:289)
at st.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247)
at st.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at st.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at st.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at st.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at cution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at cution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at cution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'dao.AssetsDevicetypeRefactorMapper' available: expected at least 1 bean which qualifies as autowire candidate. Depend at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1486)spring framework是什么框架的
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1104)
at org.springframework.beans.factory.solveDependency(DefaultListableBeanFactory.java:1066)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585)
... 35 more
[Thread-0] INFO t.support.GenericApplicationContext - Closing t.support.GenericApplicationContext@2ef3eef9: startup date [Wed Jan 09 15:45:26 CST 2019]; root of context hierarchy
Disconnected from the target VM, address: '127.0.0.1:4279', transport: 'socket'
Process finished with exit code -1
下⾯是引⼊ applicationContext*.xml ,扫描包已经改为⾃动配置的异常:
"C:\Program Files\Java\jdk1.8.0_151\" -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:4033,suspend=y,server=n -ea -lic.buffer.size=1048576 -javaagent:C:\Users\Administrator\.IntelliJIdea2018.3\system\capture Connected to the target VM, address: '127.0.0.1:4033', transport: 'socket'
[main] INFO st.context.support.DefaultTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframe
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'TestExample': Unsatisfied dependency expressed through field 'assetsDevicetypeRefactorMapper'; nested exception is org.springframework.be
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:386)
at st.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:118)
at st.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
at st.context.TestContextManager.prepareTestInstance(TestContextManager.java:230)
at st.context.ateTest(SpringJUnit4ClassRunner.java:228)
at st.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287)
at org.junit.del.ReflectiveCallable.run(ReflectiveCallable.java:12)
at st.context.hodBlock(SpringJUnit4ClassRunner.java:289)
at st.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247)
at st.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at st.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at st.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at st.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at cution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at cution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at cution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'dao.AssetsDevicetypeRefactorMapper' available: expected at least 1 bean which qualifies as autowire candidate. Depend at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1486)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1104)
at org.springframework.beans.factory.solveDependency(DefaultListableBeanFactory.java:1066)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585)
... 35 more
[main] INFO t.support.GenericApplicationContext - Refreshing t.support.GenericApplicationContext@2ef3eef9: startup date [Wed Jan 09 15:43:06 CST 2019]; root of context hierarchy [main] ERROR st.context.TestContextManager - Caught exception while allowing TestExecutionListener [st.context.support.DependencyInjectionTestExecutionListener@2f177a4b] to prepare test ins org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'TestExample': Unsatisfied dependency expressed through field 'assetsDevicetypeRefactorMapper'; nested exception is org.springframework.be at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:386)
at st.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:118)
at st.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
at st.context.TestContextManager.prepareTestInstance(TestContextManager.java:230)
at st.context.ateTest(SpringJUnit4ClassRunner.java:228)
at st.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287)
at org.junit.del.ReflectiveCallable.run(ReflectiveCallable.java:12)
at st.context.hodBlock(SpringJUnit4ClassRunner.java:289)
at st.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247)
at st.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论