【发布时间】:2010-02-12 22:09:41
【问题描述】:
我没有编写单元测试或集成测试,但现在我正在尝试。我很难设置环境。
我在 WEB-INF/applicationContext*.xml 下有我的应用程序上下文 在我的 applicationContext.xml 中,它引用了 DB 用户/密码、LDAP 主机等的属性文件
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>/WEB-INF/spring-config/dev.properties</value>
</list>
</property>
</bean>
我有另一个 log4j 配置属性(DEV/Staging/Production 的差异配置)。 ${webapp.root} 在 web.xml 中定义
<!-- log4j setting -->
<bean id="log4jInitialization" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetClass" value="org.springframework.util.Log4jConfigurer" />
<property name="targetMethod" value="initLogging" />
<property name="arguments">
<list>
<value>${webapp.root}/${log4j.properties.location}</value>
</list>
</property>
</bean>
现在我正在尝试将以下内容放入测试类中。
@Override
protected String[] getConfigLocations() {
return new String[]{
"file:trunk/code/web/WEB-INF/applicationContext.xml",
};
}
这正确引用了我的 xml,但所有属性都搞砸了。
我想知道以下内容:
- 有没有办法在测试类中正确设置?如果没有,我应该移动这些课程吗?
- 如果存在对仅存在于容器中的 webroot 的引用,我该如何设置 Log4j?!
- Spring 配置位置的最佳做法是什么?
请指教
谢谢
【问题讨论】:
-
你成功了吗?分享吧。