DEV Community

Md. Rakibul Hasan
Md. Rakibul Hasan

Posted on

Spring vs Spring Boot

Spring and Spring Boot are popular frameworks in the Java ecosystem that simplify the development of enterprise and microservices-based applications. They provide powerful features to reduce boilerplate code and improve productivity while building robust systems.

  • Enables development of scalable and production-ready applications
  • Reduces complexity through simplified configuration and auto-setup
  • Promotes modular design using reusable components

Spring
Spring is a comprehensive Java framework that provides support for building robust and scalable enterprise applications. It focuses on dependency injection, aspect-oriented programming, and modular architecture.

  • Dependency Injection (DI): Simplifies object creation and management, promoting loose coupling.
  • Modular Framework: Offers various modules like Spring MVC, Spring Security, Spring Data, allowing selective use.
  • Flexible Configuration: Supports XML, annotations, and Java-based configuration for application setup.

Example: Spring application manually configured with beans and controllers:

@Configuration
@ComponentScan(basePackages = "com.example")
public class AppConfig {
    @Bean
    public UserService userService() {
        return new UserServiceImpl();
    }
}

@Controller
@RequestMapping("/users")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping
    public String getUsers(Model model) {
        model.addAttribute("users", userService.getAllUsers());
        return "userList"; // JSP or HTML view
    }
}

// Main class deployed as WAR on external server like Tomcat
public class Main {
    public static void main(String[] args){

        // Deploy this app manually to an external server
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)