我在我的~/.m2
目录中有一个Maven settings.xml
文件;它看起来像这样:在Spring环境中使用Maven settings.xml属性
<settings>
<profiles>
<profile>
<id>mike</id>
<properties>
<db.driver>org.postgresql.Driver</db.driver>
<db.type>postgresql</db.type>
<db.host>localhost</db.host>
<db.port>5432</db.port>
<db.url>jdbc:${db.type}://${db.host}:${db.port}/dbname</db.url>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>mike</activeProfile>
</activeProfiles>
<servers>
<server>
<id>server_id</id>
<username>mike</username>
<password>{some_encrypted_password}</password>
</server>
</servers>
</settings>
我想两次
- 一旦使用Maven的
integration-test
阶段内这些属性来设置和拆除我的数据库。使用Maven过滤,这是完美的。 - 第二次运行我的Spring应用程序时,这意味着我需要在Maven的
resources:resources
阶段将这些属性替换为我的servlet-context.xml
文件。对于settings.xml
上部的属性,如${db.url}
,这可以正常工作。 我不知道如何将我的数据库用户名和(解密)密码替换为Springservlet-context.xml
文件。
我servlet-context.xml
文件的相关部分看起来像:
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName"><value>${db.driver}</value></property>
<property name="url"><value>${db.url}</value></property>
<property name="username"><value>${username}</value></property>
<property name="password"><value>${password}</value></property>
</bean>
这里的最终目标是为每个开发人员拥有(自己的机器进行集成测试上和数据库)自己的Maven的设置。 ..和Jenkins服务器上的类似设置。我们不想分享一个共同的用户名/密码/等。
关于重新编译的那一点是有效的。我肯定会更多地考虑这个问题,因为这是我希望避免的一种反模式。绝对需要这个以CI/CD风格运行。但同时,我试图重新使用已存在的信息并存储在'设置中。xml' – Mike
好吧,这是非常好的,你要重构这个。就目前而言,正如我所说的,使用这个网页资源过滤。正如你所说,它应该能够工作并使您能够在一个地方进行配置。 –
Spring 3.1为这种类型的场景引入了一些新东西:http://blog.springsource.org/2011/02/15/spring-3-1-m1-unified-property-management/ – artbristol