Thursday, July 22, 2010

Injecting enums with the Spring Framework

Today I needed to inject an Enum into a bean's constructor using Spring.

First I thought I'd need to write my own FactoryBean or 'better' a PropertyEditor.

Well no need, it is already nicely handled by the framework. After a bit of googling, I found the documentation in Appendix A of Spring's reference

And here is what actually works just fine. If I have the following enum:

public enum Language {

And the following class that I need to instantiate with Spring:

public class LocalisedLogger {
 private final Language lang;
 public LocalisedLogger(Language lang) {
   this.lang = lang;

Then I can just configure it like this:

 <bean id="logger" class="org.leberrigaud.example.LocalisedLogger">
   <constructor-arg value="FR">

That'it! Spring does the rest…

Wednesday, July 21, 2010

Java versions on Snow Leopard

It seems I have a few issues with java and versionning theses days. This time I got bitten by Java's version on Snow Leopard. Indeed whatever version you think you're using it is Java 1.6!

What got me is the JDBC api and namely the new java.sql.Wrapper interface added in 1.6. Thank god for build boxes (running Linux ;-))

I now remember that I had to install manually Java 1.5 on my work machine, when I was in Sydney. I am now working on my laptop and forgot to do that. I couldn't remember the exact procedure but someone wrote it for me. Thanks to Ted Wise!

Tuesday, July 20, 2010

Java major.minor version

You're bound to see those errors at some point if you're a java developer, something that says Unsupported major.minor version 49.0, or similar.

I always forget which number corresponds to which version of Java, so there it is:

JDK 1.4
JDK 1.5
JDK 1.6

Monday, July 12, 2010

Initialising a git-svn repo from a given date

The issue is that git-svn only lets you specify a revision number from which to init a repository. So first you have to find out the revision number at which your repository was at a given date.

You need to use SVN for that, and it's log command:

svn log -r {2009-12-31}:{2010-01-01}

This command will log all svn commits which happened between the 31st of December 2009 and the following day, 1st of January 2010.

Then from the logs just pick the commit from which you want to init your git-svn repository and there you go:

git svn clone -s -r72569:HEAD

Here the chosen revision is r72569