-
Book Overview & Buying
-
Table Of Contents
Spring Boot and Angular
By :
The following are the four main advantages of using Spring Boot to develop applications:
So, what is the difference between Spring and Spring Boot? And do you need to learn about the Spring Framework before working with Spring Boot? Let’s start with the first question.
The following table shows the difference between the two frameworks:
|
|
|
|
The developers configure the dependencies for the project. |
Using Spring Starters, Spring Boot will configure all the dependencies that will be needed to run the application. |
|
Spring is a Java EE framework for building applications. |
Spring Boot is commonly used to build REST APIs. |
|
Spring simplifies the development of Java EE applications since modules such as Spring JDBC, Spring MVC, and Spring Security are already provided. |
Spring Boot provides the configuration for the dependencies, reducing the boilerplate code for the layouts of modules. This makes it easier to run the application. |
|
Dependency injection (DI) and inversion of control (IOC) are the main features of Spring for building applications. |
Spring Boot Actuator is a feature that exposes operational information about your apps, such as metrics and traffic. |
We can identify that Spring Boot is built on top of Spring and that the main difference is that Spring Boot automatically configures the dependencies we need to run a Spring application. So, to answer the question about needing to learn about the Spring Framework before working with Spring Boot, the answer is no – Spring Boot is just an extension of Spring, which makes configuring it faster because of its opinionated approach.
Now, let’s look at the dependencies we need in Spring and Spring Boot to configure a web application.
In Spring, the minimum dependencies that we need for our application to run are Spring Web and Spring Web MVC:
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>5.3.5</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>5.3.5</version> </dependency>
Spring Boot only requires spring-boot-starter-web, which is a Spring Starter for our application to run. The necessary dependencies are added automatically at build time as the starter will be responsible for the configuration:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.4.4</version> </dependency>
Another thing to consider in Spring is that we need to define some configurations, such as dispatcher servlets and mappings, for our application to run on the server:
public class SpringInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext container) {
AnnotationConfigWebApplicationContext context =
new AnnotationConfigWebApplicationContext();
context.setConfigLocation("com.springexample");
container.addListener(new ContextLoaderListener(context));
ServletRegistration.Dynamic dispatcher =
container. addServlet("dispatcher",
new DispatcherServlet(context));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
}
After initializing the dispatcher servlets, we also need to use @EnableWebMvc and have a Configuration class with a @Configuration annotation where we will instantiate a view resolver for the applications.
A new InternalResourceViewResolver() instance will be created in the configuration class. This will be a bean for Spring. Here, all the files that are under the /WEB-INF/view path with a .jsp file extension will be resolved:
@EnableWebMvc
@Configuration
public class SpringWebConfig implements WebMvcConfigurer {
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver bean =
new InternalResourceViewResolver();
bean.setViewClass(JstlView.class);
bean.setPrefix("/WEB-INF/view/");
bean.setSuffix(".jsp");
return bean;
}
}
In Spring Boot, all these configurations will be omitted because this code is already included in the Spring Starters. We only need to define some properties for our application to run using the web starter:
spring.mvc.view.prefix=/WEB-INF/jsp/ spring.mvc.view.suffix=.jsp
After defining these properties, our application will run since all the necessary configurations, such as the Web Initializer and MVC Configuration, have been included.
With that, we have discussed the advantages of Spring Boot and, at the same time, the main differences between Spring Boot and the Spring Framework and how it reduces boilerplate code at configuration time.
As you may already know, the primary language of Spring is Java, and Java 17 has now been released. In the next section, we’ll learn about the new features in Java 17.

