Spring Boot’s First General Availability

After 18 months of development, Pivotal, sponsor of Spring and other open-source JVM technologies (e.g.: Groovy and Grails), has finally announced the general availability of Spring Boot during the first week of April. This framework is one of the components of Spring IO platform , an open-source platform that merge the core Spring APIs into a cohesive and versioned foundational platform for modern applications and offer domain-specific runtime environments (DSRs) optimized for selected application types. Spring Boot provides simplifications that will aid in developers’ productivity such as making stand-alone applications which can be initialized by ‘java-jar’ or more traditional WAR deployments . Boot also provide a command line tool that runs ‘spring scripts’.

  1. The Spring Boot Framework aims to offer the following:
  • Make stand-alone Spring applications
  • Embed Tomcat or Jetty directly (deploy WAR files is not required)
  • Offer opinionated ‘starter’ POMs to simplify your Maven configuration
  • Automatically configure Spring whenever possible
  • Provide production-ready features such as metrics, health checks and externalized configuration
  • No need for XML configuration and no code generation.

Boot is located within the “IO Execution” layer, which is allocated for domain-specific runtimes that utilize the platform’s full scope. The framework also provides opinionated fixtures for building container-less web applications. The following are reasons enumerated by the Spring Boot team, in an interview with InfoQ , as to why they decided to pursue a container-less web applications:

  • Little to configure to get coding
  • More functional deployment unit – boot builds a configured tomcat/jetty right into the JAR file!
  • Self contained executables, running them as simple as: java -jar
  • Cloud, PaaS, Virtualization friendly

The Spring Boot team also emphasized that container-less web apps are very much aligned with the Spring philosophy of being self-contained and portable. Since today’s PaaS environments provide much of the management, scale out, and reliability features already, Boot is left free to focus on developer happiness, and lightweight metrics, reporting, and an ultra light container. Boot is great for application or service deployment in the cloud, where the BYOC (Bring Your Own Container) is a natural PaaS approach, pioneered by Heroku, and embraced by CloudFoundry.

They also mentioned that container-less deployments are not mandatory on Spring Boot. Applications can still leverage the opinionated, convention-over-configuration approach that Boot offers, while deploying to their application server of choice. “If you want a container, no problem! Boot’s war files can be deployed to any Servlet 3.0-compliant application container. Some compliant containers include Tomcat 7+, Jetty 8, Glassfish 3.x, JBoss AS 6.x/7.x, and Websphere 8.0.” Spring Boot team added.

Handling Exceptions in Spring MVC with Logging

In your Spring servlet.xml, add a HandlerExceptionResolver.

	<bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
		<property name="exceptionMappings">
				<prop key="java.lang.Exception">/error/default</prop>
		<property name="defaultErrorView" value="/error/default" />
		<property name="warnLogCategory" value="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver" />

“/error/default” is the URL it will go to that will display an error message to the user. warnLogCategory is the logger category. Exceptions will be logged under the warning level and not the error level. The category value can be anything. Here we just set it to the full name of SimpleMappingExceptionResolver.

Spring HandlerExceptionResolver won’t handle errors in the view, so capture these using web.xml