Spring test mvc with Spring 3.2RC1
I had an opportunity earlier to try out Spring-test-mvc and was very impressed with how easy it now makes integration testing of the Spring MVC controllers.Spring-test-mvc is now packaged with...
View ArticleComposing Java annotations
The allowed attribute types of a Java annotations are deliberately very restrictive, however some clean composite annotation types are possible with the allowed types.Consider a sample annotation from...
View Articlecontext:component-scan, context:annotation-config and list of beans registered
A <context:component-scan/> custom tag registers the same set of bean definitions as is done by <context:annotation-config/>, apart from its primary responsibility of scanning the java...
View ArticleSpring Data JPA and pagination
Let us start with the classic JPA way to support pagination.Consider a simple domain class - A "Member" with attributes first name, last name. To support pagination on a list of members, the JPA way is...
View ArticleJson deserialization with Jackson and Super type tokens
Datatables is a jquery plugin to present tabular information - it can enhance a simple table or can use a AJAX based data and present the information in a tabular form.Datatables requires the data from...
View ArticleSpring MVC - Customizing RequestMappingHandlerMapping
When Spring MVC is configured using <mvc:annotation-driven/> in an xml bean definition file, internally a component called RequestMappingHandlerMapping gets registered with Spring MVC. This...
View ArticleJUnit test method ordering
Junit until version 4.10 uses the order of test methods in a test class as returned by the reflection API as the order of test method execution - Class.getMethods(). To quote the Javadoc of...
View ArticleWorkaround for @ContextConfiguration restriction
One of the restrictions when using @ContextConfiguration to specify the location of Spring bean configurations for a Spring based JUnit test is that only one of either the locations attribute(or...
View ArticleSpring Property Placeholder Configurer - A few not so obvious options
Spring's PropertySourcesPlaceholderConfigurer is used for externalizing properties from the Spring bean definitions defined in XML or using Java Config. There are a few options that...
View ArticleMixin in Java with Aspects - for a Scala traits sample
Scala traits allow new behaviors to be mixed into a class.Consider two traits to add auditing and version related fields to JPA entities:package mvcsample.domainimport javax.persistence.Versionimport...
View ArticleAspectj pointcut expression based on annotation on types/methods
Consider two classes, one with annotation applied on the type and one with annotation on a method:@CustomAnnotationpublic class Class1 { public void method11(){} public void method12(){}}public class...
View ArticleCGLIB and ASM inlined with Spring 3.2
This is a small change, but will go some way with issues that I have faced in the past in getting the correct dependency of CGLIB/ASM with my projects. CGLIB and its dependency ASM are now both inlined...
View Articleatan2 in scala
atan2 function is defined as follows:I wanted to try a small exercise of implementing this using scala(ignoring the fact that it is already natively implemented in java.lang.Math library).The simplest...
View ArticleSpring Bean names
Spring bean names are straightforward, except for cases where names are not explicitly specified. To start with, Spring bean names for an xml based bean definition is specified this way:<bean...
View ArticleTest fixtures - using XML Spring bean definition vs Java Configuration
Spring's Java based container configuration is a neat way of specifying Spring bean configurations and in my own projects I have systematically replaced XML configuration with Java Bean configuration...
View ArticleTest Fixtures - Using Spring scala
Continuing on my previous blog entry about creating test fixtures using Spring XML bean configuration file and the newer Spring @Configuration style, this time around I wanted to see how the same...
View ArticleSpring beans with same name and @Configuration
One of the important features when testing an application is being able to replace some of the real services with test doubles. With a Spring based application, this has typically been done by defining...
View ArticleSpring Integration File Polling and Tests
I recently implemented a small project where we had to poll a folder for new files and then trigger a service flow on the contents of the file.Spring Integration is a great fit for this requirement as...
View ArticleTesting Spring "session" scope
In a Spring based Web application, beans can be scoped to the user "session". This essentially means that state changes to the session scoped bean are only visible in the scope of the user session.The...
View ArticleGoogle guava "live" transformation - forcing an eager transformation
One of the utility classes provided by Google Guava Library, Lists, has a utility method to transform lists of one type to another. The interesting feature of this transformation is that the...
View Article