在JUnit测试中获取以下错误消息:
16:36:47,707 INFO TransactionContext:136 - Rolled back transaction for test context [DefaultTestContext@612e5caf testClass = FeedbackControllerTest, testInstance = edu.mayo.lpea.lsa.cem.controllers.FeedbackControllerTest@2ac71701, testMethod = testSubmitFeedback@FeedbackControllerTest, testException = org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'maintenanceEmailSupplier' is defined, mergedContextConfiguration = [WebMergedContextConfiguration@6303ddfd testClass = FeedbackControllerTest, locations = '{classpath*:WEB-INF/spring/app-config.xml, classpath*:WEB-INF/spring/mvc-config.xml, classpath*:WEB-INF/spring/security-config.xml, classpath:/dao-context.xml, classpath:/envDatasource-context.xml, classpath:/jndiDatasource-config.xml, classpath*:WEB-INF/spring/app-config.xml, classpath*:WEB-INF/spring/mvc-config.xml, classpath*:WEB-INF/spring/security-config.xml, classpath:/dao-context.xml, classpath:/envDatasource-context.xml, classpath:/jndiDatasource-config.xml}', classes = '{}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.test.context.web.WebDelegatingSmartContextLoader', parent = [null]]].
完整版:
@RunWith (SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@Transactional
@TransactionConfiguration
@ContextConfiguration ({"classpath*:WEB-INF/spring/app-config.xml", "classpath*:WEB-INF/spring/mvc-config.xml",
"classpath*:WEB-INF/spring/security-config.xml",
"/dao-context.xml", "/envDatasource-context.xml", "/jndiDatasource-config.xml"})
这是班上的佼佼者:
<bean id="maintenanceEmailSupplier" class="edu.mayo.lpea.ca.common.ForwardingSupplier">
<constructor-arg value="#{appPropertyDao.getSupplier('MAINTENANCE_EMAIL')}"/>
</bean>
这是在app-config.xml中:
return applicationContext.getBean ("maintenanceEmailSupplier", Supplier.class);
这是我正在调用的代码:
for i in fasta_file:
ID_list = []
sequences = []
if '>' in i:
ORF_start = i.find('>')
ORF_end = i.find('PERFECT_MATCH')
ORF_ID = i[ORF_start:ORF_end+13]
ID_list.append(ORF_ID)
print type(ID_list)
else:
sequences.append(i)
我错过了什么?为什么不找到我的豆子? (注意,摆脱类说明符并不能解决问题。)
答案 0 :(得分:0)
你的提供对我来说是不够的,因为它可能无法加载上下文文件或者可以加载上下文而不能初始化bean或缺少libs,Spring的某些命名空间。 另一方面,您应该使用两个独立环境。我的意思是一个用于测试,另一个用于生产。
所以你应该尝试将你的文件移到src / test / resources中:
并在测试类中更改注释,如下所示:
@RunWith (SpringJUnit4ClassRunner.class)
@Transactional
@ContextConfiguration ({"classpath*:/app-config.xml", "classpath*:/mvc-config.xml",
"classpath*:/security-config.xml",
"/dao-context.xml", "/envDatasource-context.xml", "/jndiDatasource-config.xml"})
让我知道我的想法是否可以帮到你,
此致