Two weeks ago I attended a Spring conference in London. It was held in a crypt under a church, which shows how creative Skillsmatter can be – even when it comes to looking for a venue
This post is an overview of what is currently happening in Spring ecosystem. Many conference talks concerned a new version of Spring that is going to be released in December. Fourth edition of framework is meant to be an evolutionary one and version bump in your config is strongly recommended by creators, who promise a smooth migration. Additionally, Spring 4 supports JDK 8, it’s developer preview was released in September (you can now grab free IntelliJ IDE and try out them lambdas! Not yet supported in Eclipse though).
First of all, I must say that after dealing with super cool and new technologies like Scala, Play! and Clojure it is a pleasure to read a good and detailed documentation of Spring. What’s more, the website is great (especially guides and forum).
Below you can find a quick run through topics I think are worth mentioning. I hope that this summary will be used as a starting point to explore Spring features in detail. All talks are available here for streaming: http://skillsmatter.com/event/java-jee/spring-exchange-1724/jb-7880
There is a number of less known or underused features of Spring that were mentioned at the conference:
- stereotype – this one is often used but not entirely understood. @Repository, @Service and @Controller are specialisations of standard @Component. The main reason for marking a class with the specialized stereotype is a more appropriate naming of the component in the layered application. Beans are easier processed by tools, and it is easy to create an AOP pointcut aiming at e.g. service beans only. Additionally, @Repository’s exceptions are automatically wrapped in DataAccessException.
- profiles – they allow setting applications to run in different configurations, for example in dev or prod mode.
- composable annotations – it is possible to create a custom annotation that aggregates a few Spring annotations together with their configuration. This way you may avoid repeating yourself with the same set of annotations over several classes.
- SpEL – Spring expression language allows creating mappings and many more. It can be used throughout the Spring configuration. It may be not fast enough if you care about performance.
- Java Validation (JSR 303) – @Valid annotation is supported in controllers, as well as annotations from javax.validation.constraints package are supported on model. Bottom line is that most of the time there is no need to write any additional code for validation.
- scheduled tasks – @Scheduled annotation (with configured task executor) allows running periodical tasks, even cron syntax can be used to define occurrences.
asynchronous methods – the task executor can be used to run methods annotated with @Async.
- context hierarchy – there can be multiple contexts with parent-child relation. Each context can be replaced in test code, or during application execution (e.g. context with logging support).
- Java configuration – there are three ways to configure Spring: using annotations, XML and Java classes with @Configurable. Choosing Java is a really good way to escape the need to have XML files in more advanced configurations, and of course it is type safe.
Here is a list of changes in Spring 4:
- Java EE 7 standards – a few standards from the newest JEE (which you’ve never used anyway) are now supported;
- event driven programming – asynchronous event driven programming known from Node.js comes to Java! Look at Spring Reactor module.
- deprecated code removed – only Java 6+ and libraries from mid 2010+ are supported.
- configuration in Groovy – fourth method of configuring beans in addition to XML, annotations and Java;
- autowiring based on generic types – it is possible to autowire before type erasure;
- HATEOAS – support for creating a discoverable API that can be now fully compliant with REST;
- conditional and programmable beans definitions – e.g. based on environment variables or other defined beans;
- custom annotations can now override attributes of meta annotations;
- Spring Messaging got extracted from Spring Integration;
introduced asynchronous calls in RESTtemplate;
- support for websockets;
Creators are also working on delivering a version of the whole “Spring platform” to make it easy to know which versions of libraries from Spring ecosystem work well together.
Spring Boot is an attempt to make Spring even leaner and allow a quick creation of services and web applications without a single line of configuration.
It’s good to keep an eye on this project and maybe, use it as a base for yet another service in microservice architecture – currently a niche of Dropwizard.
This subproject has been out there for quite a while, but I’ve never had a chance to use it. However I talked about it with a few other conference participants it looks like it’s popular. It consists of a number of integration design patterns like filters, channels, converters, etc. and configurable clients (and servers) for popular protocols like REST, SOAP or RabbitMq.
If your project integrates with a lot of different providers, Spring integration may be the way to go (Apache Camel as well).
Spring Data JPA is a project that adds really helpful features when it comes to handling relational databases. For example, it can generate queries based on a method name (there is no need for an actual implementation – an interface will do). Pagination support and API for constraints are other reasons to use it.
Various NoSql solutions and Hadoop also have their adapters in Spring data subprojects.
Spring XD (eXtreme data) is a tool for working with big, biiiig data. That’s what comes from marrying Spring Integration with Spring Batch, and adding a shell with DSL on top of it. XD may be of interest to those who have a typical big data task on their hands.
High performance applications
It is possible to create extremely performant applications in Spring. John Davies described techniques used in banking sector for transaction systems. First of all, custom binding to binary data structure is used to achieve low memory footprint. Secondly, data is retrieved in a lazy fashion. Finally, a custom Spring evaluation language compiler is implemented to enable JIT. As a result, it is possible to process 1 million transactions per second per core. I strongly recommend this talk to anyone who is interested in high frequency and low latency systems that are used in banks and telcos.
Is Java ‘the next Java’, and Spring ‘the next Spring’? That’s what one of the conference speakers argued. I must say he was pretty convincing. Spring seems to be alive and kicking.
If you managed to get that far reading this post here comes a well deserved bonus for you (scroll down):
SCREW .NET and LONG LIVE JVM! :D
( • _ •)
( • _ •)>⌐■-■