在本地测试spring openshift应用程序 [英] Testing spring openshift application locally

查看:125
本文介绍了在本地测试spring openshift应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Openshift上运行了一个应用程序。它工作正常,但测试很困难,因为我必须将每个小东西推到openshift并等待所有构建并重新启动以查看更改。

I have an application running on Openshift. It works fine, but testing is difficult because i have to push every little thing to openshift and wait for all the building and restarting to see the changes.

所以我试图找到一种在本地测试应用程序的方法。
另一个人在这里问同样的事情:如何测试本地主机上的openshift应用程序,但我想知道是否存在更简单的解决方案。

So i am trying to find a way to test the application locally. Another guy asked the same thing here: How to test an openshift application on local host, but i am wondering if an easier solution exists.

我在这里使用了quickstart项目 http://github.com/openshift/spring-eap6-quickstart.git 启动它。所以基本上它是一个使用Hibernate的Spring应用程序。

I used the quickstart project here http://github.com/openshift/spring-eap6-quickstart.git to start it. So basically it is a Spring application using Hibernate.

我想在项目中拥有两组配置文件( persistence.xml 等) ,一个用于本地Tomcat服务器,一个用于Jboss eap,
根据我要部署的服务器更改 web.xml 。这可行吗?看起来很简单,在更改
项目之前我害怕任何意外问题。

What i have in mind to have two sets of configuration files (persistence.xml etc.) in the project, one for local Tomcat server and one for Jboss eap and change web.xml according to the server i want to deploy to. Is this doable? Looks so simple, i am afraid of any surprise problems before changing the project.

推荐答案

这就是我结束的方式做起来。我重命名了原始的 web.xml 文件,其中包含 web-openshift.xml 。在OpenShift中构建项目时,将使用maven openshift 配置文件。您可以在pom.xml中的< profiles> 部分找到它。所以我在 pom.xml 中添加了一行:

This is how i ended up doing. I renamed the original web.xml file, with something like web-openshift.xml. When projects are built in OpenShift, the maven openshift profile is used. You can find it in your <profiles> section in pom.xml. So i added a line to my pom.xml:

<build>
  <plugins>
    <plugin>
      <artifactId>maven-war-plugin</artifactId>
         <configuration>
         ....
           <webXml>src/main/webapp/WEB-INF/web-openshift.xml</webXml>  <!--add this-->  

这使得 maven-war-plugin 在构建战争时使用 web-openshift.xml 文件作为Web部署描述符。然后我添加了一个 web.xml 文件,该文件将用于我的本地构建。在这些文件中,您可以使用以下命令配置servlet:

This makes the maven-war-plugin to use the web-openshift.xml file as the web deployment descriptor when building the war. Then i added a web.xml file, which will be used for my local build. In those files you configure your servlets with:

<init-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>/WEB-INF/jboss-as-spring-mvc-context.xml</param-value>

所以通过更改< param-value> 在我的两个 web.xml 文件中,我能够以不同的方式配置Spring和Hibernate。

So by changing the <param-value> in my two web.xml files, I was able to configure Spring and Hibernate in different ways.

然后我在 pom.xml中添加了标记为< provided> 的罐子/ code>到Tomcat安装的 \lib 目录。现在我能够将应用程序部署并运行到OpenShift和Tomcat。

Then I added the jars marked as <provided> in pom.xml to the \lib directory of my Tomcat installation. Now i am able to deploy and run the application both to OpenShift and Tomcat.

这篇关于在本地测试spring openshift应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆