gpt4 book ai didi

spring - 使用 Spring 运行测试。 --> java.lang.IllegalStateException : Failed to load ApplicationContext

转载 作者:行者123 更新时间:2023-12-05 00:34:56 25 4
gpt4 key购买 nike

我在运行返回 java.lang.IllegalStateException: Failed to load ApplicationContext 的测试用例时遇到问题.我已经检查了 @ContextConfiguration但看起来是对的。

类(class):

public class MainSecurityInit extends SecurityFunctionalityCbosInit
{

protected FileWriter logFile = null;
private String logFileName = "";

/* _______________________ Initializers ________________________ */
@Autowired
private CbosSecurityInit cbosSecurityInit;

public void doTest()
{

Map<Class, Object> map = new HashMap<Class, Object>();
List<DataBaseInitializerResult> results = null;

initLogFile();
try
{
// -------------- Begin of initialization ------------------ //
cbosSecurityInit.execute();
// -------------- End of initialization -------------------- //
}
catch (Throwable ex)
{
logger.error(ex.getMessage());
ex.printStackTrace();
test(results);
}
finally
{
closeLogFile();
}

}
}

SecurityFunctionalityCbosInit注释是这些:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "security-functionality-cbos-context.xml")
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false)
@Transactional
public abstract class SecurityFunctionalityCbosInit extends AbstractTransactionalJUnit4SpringContextTests{
//
}

堆栈跟踪:
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:203)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:255)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:93)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:130)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.IllegalStateException: Autowired annotation requires at least one argument: public void com.arcadia.security.MainSecurityInit.doTest()
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$2.doWith(AutowiredAnnotationBeanPostProcessor.java:307)
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:466)
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:443)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.findAutowiringMetadata(AutowiredAnnotationBeanPostProcessor.java:299)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(AutowiredAnnotationBeanPostProcessor.java:179)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:745)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:448)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:96)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:44)
at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:173)
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:199)
... 16 more

最佳答案

您要 Autowiring 的属性没有 setter ( cbosSecurityInit )。在堆栈跟踪中,有一条原因消息: Autowiring 注释至少需要一个参数:public void。

关于spring - 使用 Spring 运行测试。 --> java.lang.IllegalStateException : Failed to load ApplicationContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10102095/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com