<spring.io/projects/spring-boot>
Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run".
스프링 부트는 단독적이고, 상용화 수준의 스프링 기반 애플리케이션을 “단지 실행”할 수 있을 정도로 쉽게 만들 수 있다.We take an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss. Most Spring Boot applications need minimal Spring configuration.
<baeldung.com/spring-vs-spring-boot>
Spring Boot is basically an extension of the Spring framework, which eliminates the boilerplate configurations required for setting up a Spring application.
스프링 부트는 스프링 애플리케이션을 세팅하는데 필요한 보일러플레이트 설정들을 제거한 스프링 프레임워크의 확장이다.It takes an opinionated view of the Spring platform, which paves the way for a faster and more efficient development ecosystem.
개발 환경을 더 빠르고 편리하게 만들어주는 스프링 플랫폼이다.
최소한의 web application을 구동해야하는 경우의 의존성
<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>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.4.4</version>
</dependency>
testing libraries
spring-boot starter dependency
dispatcher servlet, mapping 등의 설정을 web.xml이나 Initializer.class에 해주어야 한다.
public class MyWebAppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext container) {
AnnotationConfigWebApplicationContext context
= new AnnotationConfigWebApplicationContext();
context.setConfigLocation("com.baeldung");
container.addListener(new ContextLoaderListener(context));
ServletRegistration.Dynamic dispatcher = container
.addServlet("dispatcher", new DispatcherServlet(context));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
}
@EnableWebMvc
@Configuration
public class ClientWebConfig implements WebMvcConfigurer {
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver bean
= new InternalResourceViewResolver();
bean.setViewClass(JstlView.class);
bean.setPrefix("/WEB-INF/view/");
bean.setSuffix(".jsp");
return bean;
}
}
아래 property만 application.properties나 application.yml에 추가
스프링 부트가 애플리케이션에 있는 dependencies, properties, beans을 보고 자동적으로 auto-configuration 수행
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
@Configuration
@EnableWebSecurity
public class CustomWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("user1")
.password(passwordEncoder()
.encode("user1Pass"))
.authorities("ROLE_USER");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.anyRequest().authenticated()
.and()
.httpBasic();
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}
기본적인 차이는 servlet에 있다.
public static void main()
이 내장 웹 서버를 실행시키기 위한 entry point이다.@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
java -jar
명령어로 독립적으로 jar를 실행시킬 수 있다.