Course – Black Friday 2025 – NPI EA (cat= Baeldung)
announcement - icon

Yes, we're now running our Black Friday Sale. All Access and Proare33% off untilnextMonday:

>>EXPLORE ACCESS NOW

Partner – Orkes – NPI EA (cat=Spring)
announcement - icon

Modern software architecture is often broken. Slow deliveryleads to missed opportunities, innovation is stalled due toarchitectural complexities, and engineering resources areexceedingly expensive.

Orkes is the leading workflow orchestration platformbuilt to enable teams to transform the way they develop, connect,and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers canfocus on building mission critical applications without worryingabout infrastructure maintenance to meet goals and, simply put,taking new products live faster and reducing total cost ofownership.

Try a14-Day FreeTrial of Orkes Conductor today.

Partner – Orkes – NPI EA (tag=Microservices)
announcement - icon

Modern software architecture is often broken. Slow deliveryleads to missed opportunities, innovation is stalled due toarchitectural complexities, and engineering resources areexceedingly expensive.

Orkes is the leading workflow orchestration platformbuilt to enable teams to transform the way they develop, connect,and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers canfocus on building mission critical applications without worryingabout infrastructure maintenance to meet goals and, simply put,taking new products live faster and reducing total cost ofownership.

Try a14-DayFree Trial of Orkes Conductor today.

eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with SpringCloud:

>> Join Pro and download theeBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockitolibrary makes it easy to writeclean and intuitive unittests for your Java code.

Get started with mocking and improve your application testsusing ourMockito guide:

Download theeBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the SpringWebFlux module, which has been improved upon ever since. Getstarted with the Reactor project basics andreactive programmingin Spring Boot:

>> Join Pro anddownload the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become astaple of Java development. The basic operations like iterating,filtering, mapping sequences of elements are deceptively simple touse.

But these can also be overused and fall into some commonpitfalls.

Toget a better understanding on how Streams work and howto combine them with other language features, check out our guideto Java Streams:

>> Join Proand download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download theE-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download theE-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download theE-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore theeBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through theLearnSpring course:

>> LEARNSPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building afullREST API with the framework:

>>The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advancedfunctionality within the Core to the deep OAuth support in theframework.

I built the security material astwo full courses - Core andOAuth, to get practical with these more complex scenarios. Weexplore when and how to use each feature andcode through it onthe backing project.

You can explore the course here:

>> Learn SpringSecurity

Partner – Orkes – NPI EA (cat=Java)
announcement - icon

Modern software architecture is often broken. Slow deliveryleads to missed opportunities, innovation is stalled due toarchitectural complexities, and engineering resources areexceedingly expensive.

Orkes is the leading workflow orchestration platformbuilt to enable teams to transform the way they develop, connect,and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers canfocus on building mission critical applications without worryingabout infrastructure maintenance to meet goals and, simply put,taking new products live faster and reducing total cost ofownership.

Try a14-DayFree Trial of Orkes Conductor today.

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle thecomplexity ofJPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided referencecourse:

>> CHECK OUT THECOURSE

Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — withOpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy toput off. That’s where OpenRewrite comes in. The open-sourceframework for large-scale, automated code transformations helpsteams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite atModerne run live, hands-on training sessions — one for newcomersand one for experienced users. You’ll see how recipes work, how toapply them across projects, and how to modernize code withconfidence.

Join the next session,bring your questions, and learn how to automate the kind of workthat usually eats your sprint time.

Partner – LambdaTest – NPI EA (cat=Testing)
announcement - icon

Regression testing is an important step in the releaseprocess, to ensure that new code doesn't break the existingfunctionality. As the codebase evolves, we want to run these testsfrequently to help catch any issues early on.

The best way to ensure these tests run frequently on anautomated basis is, of course,to include them in the CI/CDpipeline. This way, the regression tests will executeautomatically whenever we commit code to the repository.

In this tutorial, we'll see how to create regression tests usingSelenium, and then include them in our pipelineusing GitHubActions:, to berun on the LambdaTest cloud grid:

>> How to Run SeleniumRegression Tests With GitHub Actions

Course – Black Friday 2025 – NPI (cat=Baeldung)
announcement - icon

Yes, we're now running our Black Friday Sale. All Access and Proare33% off untilnextMonday:

>> EXPLOREACCESS NOW

1. Overview

The tutorial illustrates how tocreate a Web Application with Spring.

We’ll look into the Spring Boot solution for building the application and also see a non-Spring Boot approach.

We’ll primarily use Java configuration, but also have a look at their equivalent XML configuration.

Further reading:

Spring Boot Tutorial - Bootstrap a Simple Application

This is how you start understanding Spring Boot.

Configure a Spring Boot Web Application

Some of the more useful configs for a Spring Boot application.

Migrating from Spring to Spring Boot

See how to properly migrate from a Spring to Spring Boot.

2. Setting Up Using Spring Boot

2.1. Maven Dependency

First, we’ll need thespring-boot-starter-web dependency:

<dependency>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-starter-web</artifactId></dependency>

This starter includes:

  • spring-web and thespring-webmvc module that we need for our Spring web application
  • a Tomcat starter so that we can run our web application directly without explicitly installing any server

2.2. Creating a Spring Boot Application

The most straightforward way to get started using Spring Boot is to create a main class and annotate it with @SpringBootApplication:

@SpringBootApplicationpublic class SpringBootRestApplication {    public static void main(String[] args) {        SpringApplication.run(SpringBootRestApplication.class, args);    }}

This single annotation is equivalent to using@Configuration,@EnableAutoConfiguration, and@ComponentScan.

By default, it will scan all the components in the same package or below.

Next, for Java-based configuration of Spring beans, we need to create a config class and annotate it with@Configuration annotation:

@Configurationpublic class WebConfig {}

This annotation is the main artifact used by the Java-based Spring configuration; it is itself meta-annotated with@Component, which makes the annotated classes standard beans and as such, also candidates for component-scanning.

The main purpose of@Configuration classes is to be sources of bean definitions for the Spring IoC Container. For a more detailed description, see theofficial docs.

Let’s also have a look at a solution using the corespring-webmvc library.

3. Setting Up Using spring-webmvc

3.1. Maven Dependencies

First, we need thespring-webmvc dependency:

<dependency>    <groupId>org.springframework</groupId>    <artifactId>spring-webmvc</artifactId>    <version>5.3.3</version></dependency>

3.2. The Java-based Web Configuration

Next, we’ll add the configuration class that has the@Configuration annotation:

@Configuration@EnableWebMvc@ComponentScan(basePackages = "com.baeldung.controller")public class WebConfig {   }

Here, unlike the Spring Boot solution, we’ll have to explicitly define@EnableWebMvc for setting up default Spring MVC Configurations and @ComponentScan to specify packages to scan for components.

The@EnableWebMvc annotation provides the Spring Web MVC configuration such as setting up the dispatcher servlet, enabling the@Controller and the@RequestMapping  annotations and setting up other defaults.

@ComponentScan configures the component scanning directive, specifying the packages to scan.

3.3. The Initializer Class

Next, we need toadd a class that implements the WebApplicationInitializer interface:

public class AppInitializer implements WebApplicationInitializer {    @Override    public void onStartup(ServletContext container) throws ServletException {        AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();        context.scan("com.baeldung");        container.addListener(new ContextLoaderListener(context));        ServletRegistration.Dynamic dispatcher =           container.addServlet("mvc", new DispatcherServlet(context));        dispatcher.setLoadOnStartup(1);        dispatcher.addMapping("/");       }}

Here, we’re creating a Spring context using the AnnotationConfigWebApplicationContext class, which means we’re using only annotation-based configuration. Then, we’re specifying the packages to scan for components and configuration classes.

Finally, we’re defining the entry point for the web application – theDispatcherServlet.

This class can entirely replace theweb.xml file from <3.0 Servlet versions.

4. XML Configuration

Let’s also have a quick look at the equivalent XML web configuration:

<context:component-scan base-package="com.baeldung.controller" /><mvc:annotation-driven />

We can replace this XML file with theWebConfig class above.

To start the application, we can use an Initializer class that loads the XML configuration or a web.xml file. For more details on these two approaches, check outour previous article.

5. Conclusion

In this article, we looked into two popular solutions for bootstrapping a Spring web application, one using the Spring Boot web starter and other using the core spring-webmvc library.

Inthe next article on REST with Spring, I cover setting up MVC in the project, configuration of the HTTP status codes, payload marshalling, and content negotiation.

The code backing this article is available on GitHub. Once you'relogged in as aBaeldung Pro Member, start learning and coding on the project.
Course – Black Friday 2025 – NPI EA (cat= Baeldung)
announcement - icon

Yes, we're now running our Black Friday Sale. All Access and Proare33% off untilnextMonday:

>>EXPLORE ACCESS NOW

Partner – Orkes – NPI EA (cat = Spring)
announcement - icon

Modern software architecture is often broken. Slow deliveryleads to missed opportunities, innovation is stalled due toarchitectural complexities, and engineering resources areexceedingly expensive.

Orkes is the leading workflow orchestration platformbuilt to enable teams to transform the way they develop, connect,and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers canfocus on building mission critical applications without worryingabout infrastructure maintenance to meet goals and, simply put,taking new products live faster and reducing total cost ofownership.

Try a14-Day FreeTrial of Orkes Conductor today.

Partner – Orkes – NPI EA (tag = Microservices)
announcement - icon

Modern software architecture is often broken. Slow deliveryleads to missed opportunities, innovation is stalled due toarchitectural complexities, and engineering resources areexceedingly expensive.

Orkes is the leading workflow orchestration platformbuilt to enable teams to transform the way they develop, connect,and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers canfocus on building mission critical applications without worryingabout infrastructure maintenance to meet goals and, simply put,taking new products live faster and reducing total cost ofownership.

Try a14-DayFree Trial of Orkes Conductor today.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

TheApache HTTP Client is a very robust library, suitablefor both simple and advanced use cases whentesting HTTPendpoints. Check out our guide covering basic request andresponse handling, as well as security, cookies, timeouts, andmore:

>> Downloadthe eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky processwith manypotential pitfalls. A solid grasp of thefundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications withourJava Concurrency guide:

>>Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become astaple of Java development. The basic operations like iterating,filtering, mapping sequences of elements are deceptively simple touse.

But these can also be overused and fall into some commonpitfalls.

Toget a better understanding on how Streams work and howto combine them with other language features, check out our guideto Java Streams:

>> Join Proand download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring,through theLearn Spring course:

>> CHECK OUTTHE COURSE

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebasesdon’t always keep up. Frameworks change, dependencies drift, andtech debt builds until it starts to drag on delivery. OpenRewritewas built to fix that: an open-source refactoring engine thatautomates repetitive code changes while keeping developer intentintact.

The monthly training series, led by the creators and maintainersof OpenRewrite at Moderne, walks through real-world migrations andmodernization patterns. Whether you’re new to recipes or ready towrite your own, you’ll learn practical ways to refactor safely andat scale.

If you’ve ever wished refactoring felt as natural — and as fast— as writing code,this is a goodplace to start.

Course – Black Friday 2025 – NPI (All)
announcement - icon

Yes, we're now running our Black Friday Sale. All Access and Proare33% off untilnextMonday:

>> EXPLOREACCESS NOW

Course – LS – NPI (cat=REST)
announcement - icon

Get started with Spring Boot and with core Spring,through theLearn Spring course:

>> CHECK OUT THECOURSE

eBook Jackson – NPI EA – 3 (cat = Jackson)
Do JSON right with Jackson - book cover
Do JSON right with Jackson - icon
Do JSON right with Jackson
Download the E-book