<legend id='0fKwo'><style id='0fKwo'><dir id='0fKwo'><q id='0fKwo'></q></dir></style></legend>
    • <bdo id='0fKwo'></bdo><ul id='0fKwo'></ul>

      <tfoot id='0fKwo'></tfoot>

      <small id='0fKwo'></small><noframes id='0fKwo'>

        <i id='0fKwo'><tr id='0fKwo'><dt id='0fKwo'><q id='0fKwo'><span id='0fKwo'><b id='0fKwo'><form id='0fKwo'><ins id='0fKwo'></ins><ul id='0fKwo'></ul><sub id='0fKwo'></sub></form><legend id='0fKwo'></legend><bdo id='0fKwo'><pre id='0fKwo'><center id='0fKwo'></center></pre></bdo></b><th id='0fKwo'></th></span></q></dt></tr></i><div id='0fKwo'><tfoot id='0fKwo'></tfoot><dl id='0fKwo'><fieldset id='0fKwo'></fieldset></dl></div>

        我可以将来自 Maven 的属性(在 settings.xml 中定义的

        时间:2023-07-28
        • <bdo id='ixTyp'></bdo><ul id='ixTyp'></ul>
          <tfoot id='ixTyp'></tfoot>

            <tbody id='ixTyp'></tbody>

        • <i id='ixTyp'><tr id='ixTyp'><dt id='ixTyp'><q id='ixTyp'><span id='ixTyp'><b id='ixTyp'><form id='ixTyp'><ins id='ixTyp'></ins><ul id='ixTyp'></ul><sub id='ixTyp'></sub></form><legend id='ixTyp'></legend><bdo id='ixTyp'><pre id='ixTyp'><center id='ixTyp'></center></pre></bdo></b><th id='ixTyp'></th></span></q></dt></tr></i><div id='ixTyp'><tfoot id='ixTyp'></tfoot><dl id='ixTyp'><fieldset id='ixTyp'></fieldset></dl></div>

            <small id='ixTyp'></small><noframes id='ixTyp'>

                  <legend id='ixTyp'><style id='ixTyp'><dir id='ixTyp'><q id='ixTyp'></q></dir></style></legend>
                  本文介绍了我可以将来自 Maven 的属性(在 settings.xml 中定义的密码)注入到我的 Spring 容器中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我通过我在 ~/.m2/settings.xml 中为我的部署插件定义的属性定义服务器密码(不过,可以在任何地方,包括 pom.xml).我想为我的集成测试使用相同的属性.有办法吗?

                  I define passwords to servers via properties I define in my ~/.m2/settings.xml (could be anywhere, though, including pom.xml) for my deployment plugin. I'd like to use the same properties for my integration tests. Is there a way to do so?

                  如果没有,有没有一种方便的方法可以在 Maven 和 TestNG 之间共享属性?

                  If not, is there a convenient way to share properties between Maven and TestNG?

                  我想编写一个很好的测试套件,它可以在不同的持续集成服务器上运行,指向不同的远程主机(开发、测试、登台和生产),而无需修改代码.

                  I want to write a nice test suite that can run on different continuous integration servers, pointing to different remote hosts (development, testing, staging, and production), without modification of the code.

                  我在 settings.xml 中定义远程服务的凭据:

                  I am defining credentials to a remote service in settings.xml:

                  <properties>
                  <my.host>http://my.company.com</my.host>
                  <my.username>my-un</my.username>
                  <my.password>my-pw</my.password>
                  </properties>
                  

                  我希望能够使用以下方法在我的单元/集成测试 (src/test/resources) 中引用属性:

                  I'd like to be able to reference the properties in my unit/integration tests (src/test/resources) using:

                  <?xml version="1.0" encoding="UTF-8"?>
                  <beans....
                      <bean class="java.lang.String" id="un">
                          <constructor-arg value="${my.username}"/>
                      </bean>
                      <bean class="java.lang.String" id="pw">
                          <constructor-arg value="${my.password}"/>
                      </bean>
                  </beans>
                  

                  有什么选择吗?有没有其他人尝试过这个?我正在编写很多需要在我的测试中授权的 REST 测试.

                  Are there any options to doing this? Has anyone else tried this before? I am writing a lot of REST tests which require authorization in my tests.

                  谢谢!

                  推荐答案

                  当然.Maven 资源过滤 是要走的路.

                  这是一个示例配置(匹配 *-context.xml 的文件将被过滤,其他文件不会):

                  Here's a sample configuration (files matching *-context.xml will be filtered, others won't):

                  <build>
                      <resources>
                          <resource>
                              <directory>src/main/resources</directory>
                              <filtering>true</filtering>
                              <includes>
                                  <include>**/*-context.xml</include>
                              </includes>
                          </resource>
                          <resource>
                              <directory>src/main/resources</directory>
                              <filtering>false</filtering>
                              <excludes>
                                  <exclude>**/*-context.xml</exclude>
                              </excludes>
                          </resource>
                      </resources>
                  </build>
                  

                  <小时>

                  另一种方法是使用 Properties Maven 插件 到 将所有项目属性写入文件并从Spring 使用 PropertyPlaceholderConfigurer机制.


                  A different approach would be to use the Properties Maven Plugin to write all project properties to a file and reference that file from Spring using the PropertyPlaceholderConfigurer mechanism.

                  Maven 配置:

                  <build>
                      <plugins>
                          <plugin>
                              <groupId>org.codehaus.mojo</groupId>
                              <artifactId>properties-maven-plugin</artifactId>
                              <version>1.0-alpha-2</version>
                              <executions>
                                  <execution>
                                      <phase>generate-test-resources</phase>
                                      <goals>
                                          <goal>write-project-properties</goal>
                                      </goals>
                                      <configuration>
                                          <outputFile>${project.build.testOutputDirectory}/mavenproject.properties</outputFile>
                                      </configuration>
                                  </execution>
                              </executions>
                          </plugin>
                      </plugins>
                  </build>
                  

                  弹簧配置:

                  <context:property-placeholder location="classpath:mavenproject.properties"/>
                  

                  这篇关于我可以将来自 Maven 的属性(在 settings.xml 中定义的密码)注入到我的 Spring 容器中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:竹VS.Hudson(又名 Jenkins)与任何其他 CI 系统 下一篇:如何设置复杂的 Java 开发基础架构?

                  相关文章

                  最新文章

                1. <tfoot id='2GIKb'></tfoot>
                  <i id='2GIKb'><tr id='2GIKb'><dt id='2GIKb'><q id='2GIKb'><span id='2GIKb'><b id='2GIKb'><form id='2GIKb'><ins id='2GIKb'></ins><ul id='2GIKb'></ul><sub id='2GIKb'></sub></form><legend id='2GIKb'></legend><bdo id='2GIKb'><pre id='2GIKb'><center id='2GIKb'></center></pre></bdo></b><th id='2GIKb'></th></span></q></dt></tr></i><div id='2GIKb'><tfoot id='2GIKb'></tfoot><dl id='2GIKb'><fieldset id='2GIKb'></fieldset></dl></div>
                    <legend id='2GIKb'><style id='2GIKb'><dir id='2GIKb'><q id='2GIKb'></q></dir></style></legend>

                      <bdo id='2GIKb'></bdo><ul id='2GIKb'></ul>

                      <small id='2GIKb'></small><noframes id='2GIKb'>