Testing spring application with opening application locally

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

So, I'm trying to find a way to test the application locally. Another guy asked the same thing here: How to test the openshift application on the local host , but I wonder if there is a simpler solution.

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

What do I mean in order to have two sets of configuration files ( persistence.xml , etc.) in the project, one for the local Tomcat server and one for the Jboss eap and change web.xml according to the server I want to deploy to . Is this doable? It looks so simple, I'm afraid of any surprises before changing the project.

+6
source share
3 answers

This is how I ended up. I renamed the original web.xml with something like web-openshift.xml . When projects are created 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--> 

This makes the maven-war-plugin use the web-openshift.xml as a web deployment descriptor when building a war. Then I added a web.xml file that will be used for my local build. In these 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> 

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

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

+3
source

If you have a fast connection, you can run the application on the local server and let persistence.xml point to the openshift db file. To access db remotely, you will have to use port forwarding ( https://www.openshift.com/blogs/getting-started-with-port-forwarding-on-openshift ). You will need to configure the rhc client ( https://www.openshift.com/developers/rhc-client-tools-install ) and run the rhc direct access client to access the database. Then you can simply run the eclipse project on your tomcat server, and it (using persistence.xml, I assume you are using db) connects to the database. Any code changes will be considered like any other tomcat project. There is no need to have a separate web.xml for most cases (unless you have specific configurations with the ability to insert).

You can even use tools like Toad to connect to db if you want.

0
source

In an application that I ran both locally and in Openshift, I used a permanent app-root / data folder to store any specific OpenShift configuration.

In my web.xml, I include the properties as follows:

 <context:property-placeholder location="file:${user.home}/app-root/data/configuration.properties"/> 

If you manage sensitive configuration properties such as usernames and passwords, envvens variables can be long. For example, you can put the following properties in your pom.xml in the openshift profile:

 <properties> <db.username>${env.OPENSHIFT_POSTGRESQL_DB_USERNAME}</db.username> <db.password>${env.OPENSHIFT_POSTGRESQL_DB_PASSWORD}</db.password> <db.connectionURL>postgresql://${env.OPENSHIFT_POSTGRESQL_DB_HOST}:5432/${env.PGDATABASE}</db.connectionURL> </properties> 

Get database connection properties from Openshift environment variables. Then you can use maven resource filtering to put these properties in any files in specific directories, such as src / main / resources

My own local db connection properties are managed in the profile in the ~ / .m2 / settings.xml file.

This approach allows me to:

  • save all sensitive properties from my public code repository.
  • it's very easy to switch between openshift and local deployment by enabling / disabling maven build profiles.
0
source

All Articles