我不是一个Spring专家,但给了一个具有巨大上下文文件(不分成模块)的遗留系统。加载部分Spring上下文
我想添加一些单元测试 - 验证系统的不同部分,以及实际的生产配置。 然而,我开始使用ClassPathXmlApplicationContext/FileSystemXmlApplicationContext
类来加载上下文,这需要永远。 是否可以只加载部分上下文文件(递归),而不需要将原始文件分成模块?
更新: 我就张贴在这里我实现使用maven拉尔夫的解决方案: 我的pom.xml:
<plugin>
<groupId>com.google.code.maven-config-processor-plugin</groupId>
<artifactId>maven-config-processor-plugin</artifactId>
<version>2.0</version>
<configuration>
<namespaceContexts>
<s>http://www.springframework.org/schema/beans</s>
</namespaceContexts>
<transformations>
<transformation>
<input>context.xml</input>
<output>context-test.xml</output>
<config>test-context-transformation.xml</config>
</transformation>
</transformations>
</configuration>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<phase>test</phase>
</execution>
</executions>
</plugin>
我的测试情境transformation.xml:
<processor>
<add>
<name>/s:beans</name>
<value>
<![CDATA[
default-lazy-init="true"
]]>
</value>
</add>
</processor>
为什么不用你需要的beans/config为测试创建单独的配置文件,并将它们加载到测试类中? –
配置相当复杂。我想确保正确定义上下文。确保没有元素被定义两次,并且没有缺失的元素。使用整个文件还允许我遍历几个元素并对它们进行测试(请注意,我正在测试大量遗留代码,这使我可以相对快速地执行此操作)。 – krakover