将Web.xml注入Spring测试上下文

时间:2014-10-08 22:12:56

标签: spring-integration spring-test

我正在进行Web(MVC + Spring集成)应用程序的单元测试 在Tomcat上运行。 我没有将存储在web.xml中的信息包含进去 Spring Integration测试上下文。遵循

指南

http://docs.spring.io/spring/docs/3.2.0.RC1/reference/html/testing.html

我使用以下注释创建了我的JUnit类:

@WebAppConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes=MyApplicationContext.class)
public class BaseIntegrationUnitTest {...}

类MyApplicationContext正在为应用程序创建Spring集成上下文:

@EnableWebMvc
@Configuration
@ComponentScan("com.xxxxx.search.*")
@PropertySource({"file:${myPropertiesFile}"})
@ImportResource({"classpath:/META-INF/spring/integration/spring-integration-context.xml"})
public class MyApplicationContext extends WebMvcConfigurerAdapter {...}

文件/META-INF/spring/integration/spring-integration-context.xml使用了一些属性 在文件$ {myPropertiesFile}中定义了哪个特定位置  在src / resources / webapp / WEB-INF / web.xml中:

<context-param>
    <param-name>myPropertiesFile</param-name>
    <param-value>/src/main/resourcses/somePropertiesFile.property</param-value>
</context-param>    

尝试运行JUnit测试会出错:

java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 
'myPropertiesFile' in string value "file:${myPropertiesFile}"

任何人都可以给我一个提示如何&#34;注射&#34;从web.xml到的信息 Spring测试环境?

0 个答案:

没有答案
相关问题