Articles on Spring

Using Embedded Jetty With Spring MVC

  • access_time 5 years ago
  • date_range 27/11/2013
  • comment 4
  • share 11
  • label_outlineSpring, Spring MVC

Update 12/2017: Just use spring-boot-starter-jetty. For more info refer to the docs.

There could be some advantages in creating standalone web application versus packaging it as WAR and deploying it to container. Avoiding delving into debate, what I can think of is that such application could be easier to deploy/upgrade/restart, especially in situation when there are more web applications living in the container. For example, in case of Jetty, hot-deployment does not always work as expected, causing the need to restart whole thing, which in turn takes time during which applications are offline. Such app is also less prone to possible problems associated with setting up and later upgrading of the container as they come "bundled" with exact flavour they were probably integration-tested with.

Spring MVC without web.xml using WebApplicationInitializer

  • access_time 5 years ago
  • date_range 05/11/2013
  • comment 12
  • share 34
  • label_outlineSpring, Spring MVC

Update 12/2017: Thankfully this is no longer needed, really. Keeping for posterity.

Few months ago I started playing with Spring Framework, which I really enjoy. Looking for the tutorials I found some really great resources on the web as well as books. Unfortunately many of them were written for Spring 2.x, which lacks some recent features, mainly ability to configure everything by Java annotations (a.k.a. JavaConfig) rather than XML. That was something that kept me away from Spring at the first place - doing it programmatically gives much more sense of control and is more readable. So, that's what I'm trying to achieve here, I'll try to show you how to do it in more 'modern' way, showing integrations with various software packages along the way.

Setting Active Profile And Property Sources In Spring MVC

  • access_time 5 years ago
  • date_range 07/11/2013
  • comment 0
  • share 0
  • label_outlineSpring, Spring MVC

Update 12/2017: Just use Spring Boot profiles.

Often there are times when we need to access settings stored in property files depending on the environment we are in. For example database settings are likely to be different in development, testing and production environments. For this reason Spring offers a concept profile that appeared since version 3.1. That allows to selectively enable @Configuration classes for active profile thanks to @Profile annotation.

Maven Plugins To Build Frontend for Spring Boot Project

Update 12/2017: With all due respect to my Allegro buddies, there are more popular plugins for this.

To have front-end build during Maven build cycle has many advantages. Some time ago I wrote about integrating front-end build process into Maven lifecycle, by mostly writing an Ant script installing and running Grunt, and hooking it into Maven.

Static Resources in Spring 4.1

Update 12/2017: Maybe just use Spring Boot, it has all those things adjustable via

There are some new features in Spring 4.1 that allow better handling of static resources in web applications. I'm going to take a look at them, and show an application based on Spring Boot that makes use of them.

Database Connection Pooling With BoneCP in Spring Boot Application

Update 12/2017: Time passed and support for db connection pooling was build into Spring Boot. HikariCP is used by default. BoneCP is RIP.

In the following article I'll try show you how to set up a database connection pool with BoneCP and integrate it to the Spring Boot application. The database will be MySQL, and the source code for this article is based upon the source code of Spring Boot MVC application from one of the previous posts. It's recommended to get familiar with this for the people new to Spring Boot.

Developing a RESTful Web Service Using Spring Boot

Update 12/2017: Sweet, but could use an updated version. The principles seem to stand though.

I'm really impressed with Spring Boot. Its main goal is to take away most of this boilerplate configuration that was needed before and to replace it with some sensible defaults. One might say it's taking the control away from the developer and giving it to the army of fairies. That's probably right, but in this case the fairies are here to help, and moreover they can easily be cast away from doing particular thing. It's just a matter of doing it yourself as before, and thanks to @ConditionalOn... behaviour Spring Boot's auto configuration will not fire up.

In the following article I will explore the way of employing Spring Boot to create a very basic, restful web service. As usual the source code can be found here on GitHub to play around.

Spring Boot MVC application

Update 12/2017: Also could use an update.

In the last article I showed how the RESTful web service could be implemented using Spring Boot. In the following I'll make a more classical MVC application out of it, meaning real and pure, CSS-less, HTML form eye-candy.

Since there is not much difference between this and previous RESTful app, I'll focus only on what needs to be changed. And as usual, there is a source code for you to play around on GitHub, and if you want to follow the changes step-by-step, here's the source code for the RESTful web service from the previous article.