【问题标题】:Deploy production and UAT web services at once一次部署生产和 UAT Web 服务
【发布时间】:2014-08-13 12:52:45
【问题描述】:

我有一个在 Wildfly 上运行的网络服务 http://localhost:8080/ws,我使用 wildfly-maven-plugin 从 maven 部署它。

我想部署相同的 Web 服务,但指向一个测试数据源 http://localhost:8080/ws_test,这样我就可以将它用作 UAT 环境并运行测试而不影响生产数据库。

有没有简单的方法可以做到这一点?


更多信息:

  • 根(ws)在jboss-web.xml中配置:

    <jboss-web>
      <context-root>/ws</context-root>
    </jboss-web>
    
  • 我有这门课:

    @ApplicationPath("/")
    public class MyApplication extends Application { }
    
  • 我的生产数据源是“硬编码”的:

    @Resource(lookup = "java:jboss/jdbc/prod")
    private javax.sql.DataSource ds;
    
  • maven pom(摘录):

    <plugin>
      <groupId>org.wildfly.plugins</groupId>
      <artifactId>wildfly-maven-plugin</artifactId>
      <version>1.0.2.Final</version>
      <executions>
        <execution>
          <phase>install</phase>
          <goals>
            <goal>deploy</goal>
          </goals>
          <configuration>
            <hostname>localhost</hostname>
            <username>user</username>
            <password>pass</password>
          </configuration>
        </execution>
      </executions>
    </plugin>
    

【问题讨论】:

    标签: web-services jakarta-ee testing jboss wildfly


    【解决方案1】:

    我最终做的是:

    • 添加对应于测试数据库的第二个数据源:

      @Resource(lookup = "java:jboss/jdbc/test")
      private javax.sql.DataSource dsTest;
      
    • 让我的控制器知道它可以从两个 URI 调用:

      @Path("{a:(test/)?}some_page")
      public class MyController { ... }
      
    • 将调用定向到正确的数据库:

      private @Context UriInfo uriInfo;
      
      DataSource getDatasource() {
        LOG.info("in mode: {}", uriInfo.getPath());
        return uriInfo.getPath().startsWith("/test") ? dsTest : ds;
      }
      

    【讨论】:

      猜你喜欢
      • 2019-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-05
      • 2012-01-13
      • 2013-12-11
      • 1970-01-01
      • 2011-06-30
      相关资源
      最近更新 更多