CS 개념 정리

스프링과 스프링 부트의 차이

Squidward 2022. 12. 30. 15:39

스프링과 스프링 부트의 차이를 알아보기 위해서 아래 강의 하나를 들었다.

10분가량인데 재밌고 이해가 잘되니 다들 들어보시길

대략 들은 내용을 정리해보자면

먼저 Spring(봄)의 뜻은 개발자들에게 겨울은 갔다! ( = 즉 더 편하게 개발할 수 있도록 환경을 갖춰주겠다. )

그런데 Spring Boot는 Spring보다 좀 더 봄. Spring보다 더 편하게 관리해준다는 뜻이다.

 

Spring 공식 문서의 일부분으로 Spring이 왜 Spring으로 불리는지 설명한 부분이다.

Whatever happened next, the framework needed a name. In the book it was referred to as the “Interface21 framework” (at that point it used com.interface21 package names), but that was not a name to inspire a community. Fortunately Yann stepped up with a suggestion: “Spring”. His reasoning was association with nature (having noticed that I'd trekked to Everest Base Camp in 2000); and the fact that Spring represented a fresh start after the “winter” of traditional J2EE. We recognized the simplicity and elegance of this name, and quickly agreed on it.

 

스프링 부트는

Dependency나 Configuration을 자동으로 설정해주고

톰캣을 따로 쓰는 대신, 내장 서버로 embedded 서버를 알아서 구축해준다.

 

차이점 1) Dependency

먼저 Dependency를 설정해줄 때 스프링에서는 설정 파일이 길고 버전도 개발자가 일일이 기입해야한다.

아래는 스프링의 dependency 설정 코드이다.

<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>

 

아래는 스프링 부트의 dependency 설정 코드이다. (차이가 확 보인다!)

implementation 'org.springframework.boot:spring-boot-starter-web'

 

위와 같이 build.gradle 파일에 dependency를 추가해주면
Spring Boot로 웹 개발을 할 때 필요한 모든 dependency를 자동으로 추가하고 관리해준다.

 

차이점 2) Configuration

스프링은 역시 configuration 설정을 할 때도 길고 모든 어노테이션 및 빈 등록 등을 설정해줘야한다.

스프링부트는 application.properties 파일이나 application.yml 파일에 설정하면 된다.

 

아래는 스프링에서의 Configuration 설정파일이다.

@Configuration
@EnableWebMvc
public class MvcWebConfig implements WebMvcConfigurer {

    @Autowired
    private ApplicationContext applicationContext;

    @Bean
    public SpringResourceTemplateResolver templateResolver() {
        SpringResourceTemplateResolver templateResolver = 
          new SpringResourceTemplateResolver();
        templateResolver.setApplicationContext(applicationContext);
        templateResolver.setPrefix("/WEB-INF/views/");
        templateResolver.setSuffix(".html");
        return templateResolver;
    }

    @Bean
    public SpringTemplateEngine templateEngine() {
        SpringTemplateEngine templateEngine = new SpringTemplateEngine();
        templateEngine.setTemplateResolver(templateResolver());
        templateEngine.setEnableSpringELCompiler(true);
        return templateEngine;
    }

    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        ThymeleafViewResolver resolver = new ThymeleafViewResolver();
        resolver.setTemplateEngine(templateEngine());
        registry.viewResolver(resolver);
    }
}

 

아래는 스프링부트의 설정 코드이다.

차이가 확연하다.

implementation 'org.springframework.boot:spring-boot-starter-thymeleaf

 

차이점 3) 서버 배포 

스프링으로 개발한 애플리케이션은 war파일을 Web Application Server에 담아 배포했다.

반면 스프링 부트는 Tomcat, Jetty 같은 내장 WAS를 가지고 있어 jar파일로 간편하게 배포할 수 있다.

스프링처럼 WAS를 정하고 모든 설정을 거쳐 배포를 하는 것보다 확연히 간단하다.

 

 

결과적으로 스프링 부트는 개발자가 개발에만 집중할 수 있도록 편리하게 해주는 프레임 워크이다.

스프링 부트를 쓰자!

728x90