0% found this document useful (0 votes)
5 views4 pages

Spring Springboot: Purpose Used To Build Web Apps Used To Build Rest Api

Spring is primarily used for building web applications with explicit server configuration and XML setup, while Spring Boot is designed for creating REST APIs with auto-configuration and embedded servers. Spring requires manual dependency management, whereas Spring Boot simplifies this with starter projects. Additionally, Spring Boot applications can be run easily with a single command, leveraging embedded servers and simplified configuration.

Uploaded by

Hajri Azza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Spring Springboot: Purpose Used To Build Web Apps Used To Build Rest Api

Spring is primarily used for building web applications with explicit server configuration and XML setup, while Spring Boot is designed for creating REST APIs with auto-configuration and embedded servers. Spring requires manual dependency management, whereas Spring Boot simplifies this with starter projects. Additionally, Spring Boot applications can be run easily with a single command, leveraging embedded servers and simplified configuration.

Uploaded by

Hajri Azza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Spring VS SpringBoot

Purpose
Used to build Web Apps Used to build REST API
Key Functionality
Most essential features is Prime feature of Spring Boot is Auto
Dependency Injection Configuration
Use Case
Loosely Coupled Application Standalone Application
Servers
Explicit configuration of servers is Pre-Installed servers like Tomcat and
needed Jetty
XML Configuration
Required Not Required
Database
No support for in-memory database Support for in-memory database like
H2 and Tomcat
Starter Projects
Developers manually add Provides starter dependencies (e.g.,
dependencies. spring-boot-starter-web, spring-boot-
starter-data-jpa) to simplify dependency
management.
Spring Application Starts

Main Class (Bootstrapper)


Create a class with a main method to initialize the Spring container.
public class MainApp {
public static void main(String[] args) {
ApplicationContext context = new
AnnotationConfigApplicationContext(AppConfig.class);
}
}
Load Configuration
Use Java Config (@Configuration) or XML (applicationContext.xml).
@Configuration
@ComponentScan(basePackages = "com.example")
public class AppConfig {
}
Initialize ApplicationContext
ApplicationContext is created to manage beans.
AnnotationConfigApplicationContext (Java Config)
ClassPathXmlApplicationContext (XML Config)
Component Scanning
Beans are detected using @ComponentScan and @Component annotations.
Bean Creation and Injection
Spring injects dependencies using @Autowired or XML <bean>.
Lifecycle Management
Beans go through @PostConstruct and @PreDestroy for initialization and destruction.
Web App
For Spring MVC, a DispatcherServlet handles HTTP requests, routing them to
controllers.
Run Application
Deploy as WAR to Tomcat/Jetty.
No embedded server, external server is required.

Spring Boot Application Starts


Main Class with @SpringBootApplication
One class with @SpringBootApplication and a main method
@SpringBootApplication
public class MyApp {
public static void main(String[] args) {
SpringApplication.run(MyApp.class, args);
}
}
Auto-Configuration
@EnableAutoConfiguration automatically configures the app based on dependencies.
Embedded Server
Tomcat/Jetty/Undertow starts automatically.
No need for external deployment.
Component Scanning
@SpringBootApplication includes @ComponentScan to detect beans.
Bean Creation and Injection
Spring Boot manages dependencies with @Autowired and @Bean.
Web App (Optional)
Add REST controllers with @RestController.
@RestController
public class HelloController {
@GetMapping("/hello")
public String hello() {
return "Hello, Spring!";
}
}
Run Application
Run via java -jar app.jar or directly from IDE.
Embedded server listens on localhost:8080 by default.

You might also like