Category: Uncategorized

  • Log4j and Tomcat issue

    (Recovered from my old Blog). Quick one – I had this issue today so wanted to record it for posterity. Tomcat can get confused if WEB-INF/lib contains the log4j jar, with initialisation errors such as: java.lang.ClassNotFoundException: org.apache.log4j.Category You might not even have directly included it – it might be included via a Maven dependency. The […]

  • Spring Security 3 Setup

    (Recovered from my old Blog). Getting Spring Security setup only involves a few steps, but it can be confusing to work out exactly what they are – especially since almost all documentation refers to Spring Security 2, and there are a couple of differences. The first thing to do is to add the Spring Security […]

  • SiteMesh with Spring MVC

    (Recovered from my old Blog). SiteMesh is an open source framework that implements the Decorator pattern. It essentially takes the output stream from a web application, and adds elements to (’decorates’) it. Why would we want that? Put simply, it is an incredibly clean way of adding headers/footers/anything, with the underlying jsp (or whatever) having […]

  • Converting Spring MVC XML bean definitions into annotations

    (Recovered from my old Blog). As of Spring 2.5, annotations can be used on Spring MVC classes instead of defining each and every page in the *-servlet.xml definition file. However, most online guides still reference the old practice. Below is a simple guide to migrating to (in my opinion), the much cleaner annotation approach. ‘Normal’ […]

  • Breaking Up A Large Hibernate Class

    (Recovered from my old Blog). Over time, Hibernate classes can get very large – especially when modelling a complicated object (for example a financial transaction). At this point, the @Embedded annotation comes to the rescue. The class annotated with @Embedded will be linked into the parent class as if it were one large class. This […]

  • Simple Database Population Tool

    (Recovered from my old Blog). My source control contains many tables, many of which have dependencies on one another via foreign keys. When the table structures are being changed fairly regularly, it can be a pain to have to keep updating the database manually. Ant has a built in SQL task which will pick up […]

  • Create an enum dynamically

    (Recovered from my old Blog). When creating an enum dynamically, there are two levels of difficulty. The first case is where the type of the enum is known at compile-time, but the value is not. In this case, we can use the valueOf method of the enum in question: [crayon-669619781f5dd232073519/] The second, more complex case […]

  • Sharing Resources between Maven modules

    (Recovered from my old Blog). I needed to share resources between modules in a multi-module Maven project. The resources in question are configuration data files which are converted into objects via XStream (plus some Spring Bean configuration files). The reason they need to be shared is for instantiation within module-specific JUnit tests. After some thinking […]

  • Injecting Resources into Spring Beans

    (Recovered from my old Blog). This is mentioned in passing in the Spring documentation – but to highlight: Spring will automatically convert a String in a bean definition into a Resource if required. If the target Resource is a specific class (e.g. UrlResource) then the passed in string must match the format, or a runtime […]

  • Persisting a Collection with an arbitrary enum type

    (Recovered from my old Blog). As we know, enums are great for storing (relatively) static domain information. But let’s say we want an object which models (and can persist) a collection of elements where we are not sure at design time which domain information will be stored. For example, a set of attributes describing a […]