在JUnit測試獲得以下錯誤消息:春告訴我一個bean的名稱沒有定義,當它是
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'maintenanceEmailSupplier' is defined
完整版:
16:36:47,707 INFO TransactionContext:136 - Rolled back transaction for test context [[email protected] testClass = FeedbackControllerTest, testInstance = [email protected]1, testMethod = [email protected], testException = org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'maintenanceEmailSupplier' is defined, mergedContextConfiguration = [[email protected] 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"})
這是在app-config.xml中:
<bean id="maintenanceEmailSupplier" class="edu.mayo.lpea.ca.common.ForwardingSupplier">
<constructor-arg value="#{appPropertyDao.getSupplier('MAINTENANCE_EMAIL')}"/>
</bean>
這是我打電話的代碼:
return applicationContext.getBean ("maintenanceEmailSupplier", Supplier.class);
我缺少什麼?爲什麼不找到我的豆子? (請注意,刪除類說明符並不能解決問題。)
是'WEB-INF /春/ APP-config.xml'測試運行的classpath的一部分嗎? –
是的。當我嘗試運行單元測試時,該文件中的錯誤會導致問題 –