Posted in Java

Setting up a Vagrant Java 8 Environment

Pretty simple setup thanks to Rob Murray’s Vagrant Java dev box setup.

Some of the issues I encountered with this setup were pretty easy to overcome, but I thought I would outline them here and eventually provide feedback to the author for completeness.

First of all I am using a Windows 7 host with VirtualBox 4.2.16, Vagrant 1.7.2 and git (on Windows 1.9.5.msysgit.0).

Follow the instructions within the link above.¬†Apparently, the method of pulling the required source from git in one of the steps does not use the correct protocol so you will need to edit the following files within the “vagrant-javadev-box” directory:

.git/config

.gitmodules

Change all occurrences of git:/ and git@ with https:// because public access to GitHub repositories may only work with https.

For me Vagrant did not automatically setup/install the Java 8 JRE so I needed to do it manually.

Install the appropriate package so you can run the “add-apt-repository” command which specifies the appropriate repository where the Java 8 installation package is found.

sudo apt-get install python-software-properties

Install the repository

sudo add-apt-repository ppa:webupd8team/java

sudo apt-get update

sudo apt-get install oracle-java8-installer

sudo apt-get install oracle-java8-set-default

Posted in Java, Spring framework

Defining HibernateExceptionTranslator

I wanted to avoid defining any Spring bean XML configuration generally for my Spring apps. Firing up Jetty with Maven, you may sometimes encounter the following:

java.lang.IllegalStateException: No persistence exception translators found in bean factory. Cannot perform exception translation. at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.

When defining your beans using annotations in Spring, simply specify a method annotated with @Bean that returns an instance of HibernateExceptionTranslator. The method name can be arbitrary.