How to Deploy Spring Boot Applications to Tomcat Application Server

We sometimes encounter a variety of application servers to deploy in our projects due to the different customers we work with. Although Spring Boot has a built-in Embedded Tomcat server, this is mainly used for development or microservice deployment. If you end up deploying your application to a client’s Tomcat / JBoss EAP / IBM WebSphere environment, you still need to make some adjustments. Today’s article is an in-depth look at the setup process and complete knowledge of deploying to Apache Tomcat®.

Native Support in Spring Boot 3.0.0-M5

The Spring Team has been working on native image support for Spring Applications for quite some time. After 3+ years of incubation in the Spring Native experimental project with Spring Boot 2, native support is moving to General Availability with Spring Framework 6 and Spring Boot 3! Native images provide almost instant startup time and reduced memory consumption for Java applications. The recent Spring Boot 3.0.0-M5 release marks the first time we’re asking for broader community feedback on our native story.

Spring Profiles in Spring Boot

In any set of development frameworks, multi-environment management is usually one of the important core features, of course, in the Spring framework is no exception, here we call the Spring Profiles. This feature is simple to say, but it is easy to accidentally mess up the implementation, this article I intend to properly sort out some of the concepts to understand, the management up to not mess up. Create sample applications Quickly building a project using the Spring Boot CLI

PathPattern In Spring MVC

Spring 5 has also been out for a long time, there are some new things we need to explore slowly. Recently, when I was looking at the SpringMVC source code, I saw the following piece of code. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 /** * Initialize the path to use for request mapping. * <p>When parsed patterns are {@link #usesPathPatterns() enabled} a parsed * {@code RequestPath} is expected to have been * {@link ServletRequestPathUtils#parseAndCache(HttpServletRequest) parsed} * externally by the {@link org.

@SpringBootApplication in Spring Boot

When I’m learning a new framework, I like to look at things that beginners don’t like to read or don’t understand. For example, when I was learning Angular, it was obvious that ng new would be enough to create a new project and start writing programs, but I would go deeper into the whole process of starting it. And when I was learning Spring Boot, even though Spring Initializr was really nice to use, and I could start developing applications by just selecting the packages, I wanted to understand what was going on behind the scenes of this amazing design, so I could understand the core principles of a framework.

Formatting json Date/LocalDateTime/LocalDate in Spring Boot

Spring Boot uses jackson by default to serialize, deserialize json data. By default, Jackson serializes Date objects as timestamps. For LocalDateTime, LocalDate objects, jackson doesn’t do anything special, it just treats them as basic Java objects. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 import java.time.LocalDate; import java.time.LocalDateTime; import java.util.Date; import java.util.HashMap; import java.util.Map; import com.

Getting started with your first spring boot application from scratch

Spring Boot has been gaining traction in the Java community for a few years now, but instead of reinventing the wheel, it has integrated a bunch of good, off-the-shelf packages and designed some simple programming frameworks with IoC and AOP to greatly simplify the complexity of development and reduce the number of tedious setup steps. Instead of using Spring Initializr to get you started, I’m going to completely hand-carve the Spring Boot application and dissect the entire development and startup process from scratch.

Map a JSON POST to Multiple Spring MVC Parameters

1. Overview When using Spring’s default support for JSON deserialization, we’re forced to map the incoming JSON to a single request handler parameter. Sometimes, however, we’d prefer a more fine-grained method signature. In this tutorial, we will learn how to use a custom HandlerMethodArgumentResolver to deserialize a JSON POST into multiple strongly-typed parameters. 2. The Problem First, let’s look at the limitations of Spring MVC’s default approach to JSON deserialization.

Setup of spring boot application & initialization of PostgreSQL database on Kubernetes

Reference Setup of spring boot application & initialization of PostgreSQL database on Kubernetes - PART 1 Setup of spring boot application & initialization of PostgreSQL database on Kubernetes - PART 2 How to deploy a containerized spring boot application , with PostgreSQL as database on minikube. This post will also share details on how to initialize the database with tables and data during the initialization process. Will use a spring boot application order service with a REST endpoint to fetch customer details

Quickly Developing Spring Boot Applications with Spring Boot CLI

Spring Boot CLI Introduction The Spring Boot CLI is a command line tool (CLI Tool) that you can use to help you quickly develop a Spring application if you want to do so. You just need to write a Groovy script first, and then you can immediately run a Spring Boot application through the Spring Boot CLI. Of course, you can also use the Spring Boot CLI to quickly build a Spring Boot project based on Maven or Gradle (via the Spring Initializr service).

How to Deploy Spring Boot Applications to WildFly Application Server

The open source WildFly Application Server (WildFly AS) is an upstream project of the commercial JBoss EAP (Enterprise Application Server). This means that JBoss EAP is based on WildFly AS, and you will probably know how to deploy to JBoss EAP once you learn how to deploy applications to WildFly AS. In today’s article, I’m going to introduce how to deploy a Spring Boot application to the WildFly application server.

Spring MVC ViewResolver

ViewResolver Overview The role of ViewResolver component is to resolve the corresponding view View object based on the view name and the localized Locale. In the SpringMvc source code, ViewResolver is an interface. This interface defines one method. View resolveViewName(String viewName, Locale locale) The interface method takes two parameters viewName and locale, viewName is the view name and locale is the localization parameter. In general, we only need the viewName to find the corresponding view.

Unit and Integration Testing in Spring Boot Micro Service

Let’s write tests using Mockito and JUnit Hello guys!!! How is your day? I thought of focusing on testing side this time. If you are a good developer, you should be able unit test the functionalities you are implementing. Then developer also can assure that the feature is working fine in a technical manner. This is an additional advantage that we get. So, I’m trying to show you how to write simple unit tests and integration tests for a Spring Boot application.

SpringSecurity-new objects can also be managed by the Spring container

It is reasonable to say that the new objects and the container are not related, but in the Spring Security framework also new a lot of objects out, but also can be managed by the container. How is this done? In the Spring Security authorization configuration code of some projects, you will find a line of code like this. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 @Configuration public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.

Gracefully record the payload of an HTTP request or response

Often encounter the need to handle http requests and response body scenarios. One of the bigger problems here is that once the requestBody or responseBody stream of a servlet has been read, it cannot be read again. For this problem, Spring itself provides a solution, namely. ContentCachingRequestWrapper ContentCachingResponseWrapper Write a filter. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 public abstract class HttpBodyRecorderFilter extends OncePerRequestFilter { private static final int DEFAULT_MAX_PAYLOAD_LENGTH = 1024 * 512; private int maxPayloadLength = DEFAULT_MAX_PAYLOAD_LENGTH; @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { boolean isFirstRequest = !

Using StopWatch elegantly outputs the time spent on execution

Background Sometimes we need to record the execution time of each task when doing development, or record the execution time of a piece of code, the simplest way is to print the difference between the current time and the execution time, and then if the implementation of a large number of tests is very troublesome, and not intuitive, if you want to do further control of the execution time, it is necessary to modify many places in the program.

Creating a custom Spring Cloud Gateway Filter

In this article, we look into writing a custom extension for Spring Cloud Gateway. Before we get started, let’s go over how Spring Cloud Gateway works: First, a client makes a network request to the Gateway The Gateway is defined with a number of routes, each with Predicates to match the request to the route. For example, you can match on the path segment of the URL or the HTTP method of the request.

Apache HttpClient 5 tutorial

Hypertext Transfer Protocol (HTTP) is probably one of the most important protocols on the Internet today. Web services, microservices, and services on various devices that support the Web are almost all HTTP, and the HTTP protocol has moved from Web browsers to a wider range of usage scenarios. Although the java.net package already provides the basic functionality for HTTP access to resources, it is not flexible enough and cannot be

Introducing Experimental Spring Support for Apache Pulsar

We are happy to announce that we are incubating a new experimental Spring project for Apache Pulsar. This project aims to provide Spring-friendly APIs, building blocks, and programming models for writing Java applications that interact with Apache Pulsar. Apache Pulsar is a popular messaging system with a growing ecosystem of developers in the enterprise messaging and streaming space. Here are some main features and advantages of using Apache Pulsar for messaging-based software applications:

Quickly bootstrap a new Spring Boot project with the Spring CLI

Generating a Spring Boot project can be made through various means, each having its own use case depending on your situation. You can use the Spring Initializr web UI which is beginner-friendly and perfect to get an overview of what is available. You can also generate your project inside your favorite IDE like Eclipse or Intellij by using plugins. And finally, you can generate your project without leaving your shell with the Spring CLI, and that is what we are going to do.