Debugging Spring REST bad request 400 codes

This happens way too often: you POST or PUT something to a Spring @RestController and Spring only tells you that there is a bad request, HTTP 400 code; no further explanations, no logs, no exceptions. Spring logs the error cause under the category "org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod" so you can enable logging for that in your log4j.properties: log4j.logger.org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod=DEBUG,stdout … Continue reading Debugging Spring REST bad request 400 codes

Spring MVC REST controller says 406 when emails are part URL path

You've got this Spring @RestController and mapped a URL that contains an email as part of the URL path. You cunningly worked around the dot truncation issue [1] and you are ready to roll. And suddenly, on some URLs, Spring will return a 406 [2] which says that the browser requested a certain content type … Continue reading Spring MVC REST controller says 406 when emails are part URL path

LocalContainerEntityManagerFactoryBean, Hibernate and superflous tables created in wrong database

TL;DR Hibernate's (3.2-3.4) JPA implementation will pick up hbm files on it's own when it should be looking only at persistence.xml, thus: - loading more entities that it should - loading the wrong entities - performing schema updates in the wrong database This one annoyed me plenty and took a great deal of debugging to … Continue reading LocalContainerEntityManagerFactoryBean, Hibernate and superflous tables created in wrong database

Tomcat, Spring and memory leaks when undeploying or redeploying an web application

In this post I'll talk about a new kind of memory leak in Spring applications involving transaction management and initializing beans. About memory leaks when undeploying a web application While developing a web application with Spring and Tomcat I frequently run out of heap space. The web is full of stories about this. There is … Continue reading Tomcat, Spring and memory leaks when undeploying or redeploying an web application

Spring @Value and resolving property names with dots

I'm moving a legacy application (I seem to be doing that a lot recently) to Spring and injecting properties with @Value into Spring managed beans all over the place. And it doesn't work: public class SomeService{ @Value("#{the.org.namespace.someProperty}") private String someProperty; } Dots have apparently a special meaning, so this fails with a message that 'the' … Continue reading Spring @Value and resolving property names with dots

Liferay diaries: Multiple spring form controllers in a portlet

Now there comes a moment in the life of every portlet author, be it a seasoned veteran (like jstam) or a fresh starter like myself when you need to do implement something out of the ordinary for which portlets were not intended. Last week we had to scetch up an all-in-one portlet that could display … Continue reading Liferay diaries: Multiple spring form controllers in a portlet

Liferay diaries: Serving resources from a portlet with Spring

So there comes the day when you finally have to serve an image, pdf or excel report generated by a portlet or, more elegantly, by a Spring controller backing a portlet. At a first take this may seem impossible since the markup produced by a portlet is embedded in the markup (i.e. HTML) of all … Continue reading Liferay diaries: Serving resources from a portlet with Spring

Spring @PathVariable mapping incomplete path when dots are included

In all my projects this happens at least once, and I'm surprised over and over again: a controller will not map just anything to @PathVariable by default. Contrary to intuition, the annotation's argument is a regular expression which excludes some characters per default. For instance the url http://localhost:8080/myapp/api/user/testuser@example when mapped to a controller: @RequestMapping(value = … Continue reading Spring @PathVariable mapping incomplete path when dots are included

Cache collision and ehcache spring annotations module

If you are looking for a way to implement declarative caching with Spring, there is no way around Ehcache Spring Annotations [1]. This superimposes a transparent aspect on methods of any proxied bean, taking the method arguments as a key. Little known but easy to stumble upon [2] is an implementation (design?) quirk which expects … Continue reading Cache collision and ehcache spring annotations module