使用maven时,开发环境与部署的不同spring XML文件

[英]Different spring XML files for development environment vs. deployment when using maven


Summary

We have a central LDAP server that our deployed Java web app should connect to. Our JUnit tests depend on specific data in the LDAP repository, so they need to connect to an embedded ApacheDS LDAP server, primed with a sample data set. How do we make sure that the ApacheDS server doesn't start up when we deploy our webapp?

我们有一个中央LDAP服务器,我们部署的Java Web应用程序应连接到该服务器。我们的JUnit测试依赖于LDAP存储库中的特定数据,因此他们需要连接到嵌入式ApacheDS LDAP服务器,并使用示例数据集进行准备。在部署我们的webapp时,我们如何确保ApacheDS服务器无法启动?

Details

We are using Spring security, and have the following line in ldap-context.xml to start up the embedded LDAP server:

我们正在使用Spring安全性,并在ldap-context.xml中使用以下行来启动嵌入式LDAP服务器:

<security:ldap-server root="dc=test,dc=com" port="33389" ldif="classpath:EmbeddedServerRoot.ldif" />

Currently, our web.xml references both this test context file and our top-level application-context.xml:

目前,我们的web.xml引用了此测试上下文文件和顶级application-context.xml:

    <context-param>
       <param-name>contextConfigLocation</param-name>
       <param-value>
           classpath:ldap-context.xml
           classpath:application-context.xml 
       </param-value>
   </context-param>

We need to make sure that ldap-context.xml is included when we run our JUnit tests, and when we run the webapp directly from eclipse (via WTP), but excluded when we package the war and deploy it to a server.

我们需要确保在运行JUnit测试时以及当我们直接从eclipse(通过WTP)运行webapp时包含ldap-context.xml,但在我们打包war并将其部署到服务器时排除。

We're using maven as the build tool. We can fairly easily take care of this situation for our JUnit tests by making sure they include both spring context files in the context configuration:

我们使用maven作为构建工具。我们可以通过确保它们在上下文配置中包含两个spring上下文文件来相当轻松地处理JUnit测试的这种情况:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:ldap-context.xml", "classpath:application-context.xml" })
public class TestStuff {
}

Then, our web.xml would only include application-context.xml, except for one thing - this doesn't work when running from WTP - we need the embedded server to start up in that case as well. Any suggestions?

然后,我们的web.xml将只包含application-context.xml,除了一件事 - 从WTP运行时这不起作用 - 我们也需要嵌入式服务器在这种情况下启动。有什么建议?

2 个解决方案

#1


1  

If you're using Maven, why not use the Assembly plugin to manage your environment deployments. It seems like your spring file is not that complex, so you can have a common spring file which doesn't have the ldap-context.xml reference, and then a test-specific version which does have the ldap reference. When assembly is configured and run, the environment specific file will overwrite the common version, and then you can deploy your packaged app.

如果您正在使用Maven,为什么不使用Assembly插件来管理您的环境部署。看起来你的spring文件并不复杂,所以你可以有一个没有ldap-context.xml引用的公共spring文件,然后是一个测试专用的版本,它有ldap引用。配置并运行程序集时,特定于环境的文件将覆盖通用版本,然后您可以部署打包的应用程序。

#2


0  

An other possibility is to use some properties in the pom and a filtered spring bean file defining aliases for the beans to switch between environments. But you need to habe both beans in the config, but you will use the one or the other.

另一种可能性是在pom中使用一些属性,并使用过滤的spring bean文件定义bean的别名以在环境之间切换。但是你需要在配置中使用两个bean,但是你将使用其中一个。

智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2008/10/16/b8545250e62326e67905d94ab62cf30c.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告