본문 바로가기
카테고리 없음

[스터디] 스프링 부트 개념과 활용 - 4주차 ( ~ 3/13)

by shakevan 2022. 3. 12.

SpringApplication

https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#features.spring-application

 

Spring Boot Reference Documentation

This section goes into more detail about how you should use Spring Boot. It covers topics such as build systems, auto-configuration, and how to run your applications. We also cover some Spring Boot best practices. Although there is nothing particularly spe

docs.spring.io

- SpringApplication의 기본 log level은 INFO

 

Springboot Application을 실행하는 3가지 방법

@SpringBootApplication
public class SpringbootApplication {

	/**
	 * 1안) 추가적인 커스터마이징이 불가
	 */
	public static void main(String[] args) {
		SpringApplication.run(SpringbootApplication.class,args);
	}

	/**
	 * 2안) 객체 생성 후 set
	 */
	public static void main(String[] args) {
		final SpringApplication springApplication = new SpringApplication(SpringbootApplication.class);
		springApplication.setWebApplicationType(WebApplicationType.NONE);
		springApplication.run(args);
	}

	/**
	 * 3안) builder를 활용
	 */
	public static void main(String[] args) {
		new SpringApplicationBuilder()
			.sources(SpringbootApplication.class)
			.web(WebApplicationType.NONE)
			.run(args);
	}
}

 

SpringApplication Event

https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#features.spring-application.application-events-and-listeners

 

Spring Boot Reference Documentation

This section goes into more detail about how you should use Spring Boot. It covers topics such as build systems, auto-configuration, and how to run your applications. We also cover some Spring Boot best practices. Although there is nothing particularly spe

docs.spring.io

 

- ApplicationContext가 뜨기 이전의 EventListener들은 Bean으로 등록해도 동작하지 않는다. 그렇기 때문에 아래와 같이 직접 Listener를 등록해주어야 함

@SpringBootApplication
public class SpringbootApplication {

	public static void main(String[] args) {
		final SpringApplication springApplication = new SpringApplication(SpringbootApplication.class);
		springApplication.addListeners(new SampleListener()); //Listener를 직접 등록
		springApplication.setWebApplicationType(WebApplicationType.NONE);
		springApplication.run(args);
	}
}

 

 

WebApplicationType

https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#features.spring-application.web-environment

 

Spring Boot Reference Documentation

This section goes into more detail about how you should use Spring Boot. It covers topics such as build systems, auto-configuration, and how to run your applications. We also cover some Spring Boot best practices. Although there is nothing particularly spe

docs.spring.io

 

Application Arguments

https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#features.spring-application.application-arguments

 

Spring Boot Reference Documentation

This section goes into more detail about how you should use Spring Boot. It covers topics such as build systems, auto-configuration, and how to run your applications. We also cover some Spring Boot best practices. Although there is nothing particularly spe

docs.spring.io

 

VM Options vs Application arguments Options

- -D로 시작하는건 VM

- --로 시작하는건 Application arguments

 

ApplicationRunner / CommandLineRunner

- SpringApplication이 실행된 후 특정 코드를 한번 수행하고 싶을 때 사용

If you need to run some specific code once the SpringApplication has started, you can implement the 
ApplicationRunner or CommandLineRunner interfaces.

https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#features.spring-application.command-line-runner

 

Spring Boot Reference Documentation

This section goes into more detail about how you should use Spring Boot. It covers topics such as build systems, auto-configuration, and how to run your applications. We also cover some Spring Boot best practices. Although there is nothing particularly spe

docs.spring.io

 

 

외부 설정

https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#features.external-config

 

Spring Boot Reference Documentation

This section goes into more detail about how you should use Spring Boot. It covers topics such as build systems, auto-configuration, and how to run your applications. We also cover some Spring Boot best practices. Although there is nothing particularly spe

docs.spring.io

- 위 문서에 정의되어 있는 우선순위에 따라 외부 설정파일을 읽어들여옴

   - 우선순위가 높은 key값이 아래 우선순위의 key값을 오버라이딩(덮어씀!)

 

 

application.properties들의 위치

https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#features.external-config.files

 

Spring Boot Reference Documentation

This section goes into more detail about how you should use Spring Boot. It covers topics such as build systems, auto-configuration, and how to run your applications. We also cover some Spring Boot best practices. Although there is nothing particularly spe

docs.spring.io

 

ConfigurationProperties

https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#features.external-config.typesafe-configuration-properties

 

Spring Boot Reference Documentation

This section goes into more detail about how you should use Spring Boot. It covers topics such as build systems, auto-configuration, and how to run your applications. We also cover some Spring Boot best practices. Although there is nothing particularly spe

docs.spring.io

 

@Validated

https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#features.external-config.typesafe-configuration-properties.validation

 

Spring Boot Reference Documentation

This section goes into more detail about how you should use Spring Boot. It covers topics such as build systems, auto-configuration, and how to run your applications. We also cover some Spring Boot best practices. Although there is nothing particularly spe

docs.spring.io

 

 

Profiles

https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#features.profiles

 

Spring Boot Reference Documentation

This section goes into more detail about how you should use Spring Boot. It covers topics such as build systems, auto-configuration, and how to run your applications. We also cover some Spring Boot best practices. Although there is nothing particularly spe

docs.spring.io

 

- spring.profiles.group vs spring.profiles.include

2.4 버전 이상에서 부터 group을 사용해야하는듯

 

참고 : 

http://honeymon.io/tech/2021/01/16/spring-boot-config-data-migration.html

https://github.com/mindock/spring-boot-practice/wiki/4%EC%A3%BC%EC%B0%A8-%EC%8A%A4%ED%84%B0%EB%94%94#spring-boot-24-%EC%9D%B4%EC%A0%84-%EB%B2%84%EC%A0%84

 

댓글