Skip to main content

Spring

Spring Boot Starters

This post discusses Spring Boot Starters and their importance to developers, who want to make the setup and configuration of Spring Boot applications a whole lot easier. It keeps dependencies organized, increases development speed, and grants you numerous options for customization and extension. This basically makes them indispensable in building all manner of applications with Spring Boot - from simple web applications to data access and security services. I showcase, with a practical example, how to create a custom Spring Boot Starter that consolidates logging configurations and standard dependencies across microservices. This guide provides step-by-step instructions on how to create and use a custom starter.

Spring Boot Configuration Best Practices

Spring Boot comes with very neat configuration mechanism. Default application configuration is defined in one configuration file and environment specific setting in separate files. But still, this mechanism is often not used properly resulting in verbose and unmaintainable configurations.

Customizing REST API Error Response in Spring Boot / Spring-Security-OAuth2

Defining error format is important part of REST API design.

Spring-Boot and Spring Security provide pretty nice error handling for RESTful APIs out of the box. Although it has to be documented, especially when contract-first approach to API design is used.

It is good idea to follow some common format for error responses. But OAuth2 specification and Spring Boot format may not satisfy those requirements.

Booting Spring Webapp

Spring Boot is an excellent tool to bootstrap java application. Most of the references mention how to create a standalone java application, optionally with embedded web server (tomcat or jetty). But Spring Boot supports also creating web applications intended to run within servlet container.

Conditional Java Configurations in Spring Framework

Spring Framework offers very flexible means for binding application components. Externalizable properties, composite configuration, nested application contexts and profiles.

Sometimes, it is necessary to control whether particular beans or @Configuration will be loaded or not. Spring Framework v.4.1.x does not provide that feature out of the box. But, hopefully, Spring allows conditional bean initialization (see @Profile implementation and @Configurable). So, I created the annotation @Enabled which allows me to control bean instantiation via properties.

@Enabled indicates that a component is eligible for registration when evaluated expression is true. This annotation should be used in conjunction with Configuration and Bean annotations.

Establishing Customizable Tomcat Configuration

Deploying to Apache Tomcat often requires making changes to default configuration. These changes are often environment specific. Also, when upgrading a Tomcat to new version you need to be sure that all your custom changes have not been lost and were applied to new configuration. To deal with all that stuff Tomcat via separation of the configuration. This post contains step-by-step instruction will help you to establish custom tomcat configuration.