ApplicationContext extends ResourceLoader ApplicationContext가 상속받는 것중 ResourceLoader에 대해 살펴보자 리소스가 읽어오는 기능을 제공하는 인터페이스다. 리소스를 읽어오는 방법 파일 시스템 읽어오기 classpath에서 읽어오기 target/classes가 root가 되고 이 밑으로 찾게 리소스를 찾게된다. @Component public class AppRunner implements ApplicationRunner { @Autowired ResourceLoader resourceLoader; @Override public void run(ApplicationArguments args) throws Exception { Resource re..
ApplicationContext extends ApplicationEventPublisher ApplicationContext가 상속받는 것중 ApplicationEventPublisher에 대해 살펴보자 Event 만들어보기 스프링 4.2 전에는 ApplicationEvent를 상속 받은 후 Event를 만들어야 했으나, 그 이후 부터는 해당 클래스를 상속받지 않아도 Event로 사용할 수 있다. public class MyEvent { private int data; private Object source; public MyEvent(Object source, int data) { this.source = source; this.data = data; } public Object getSource(..
ApplicationContext extends MessageSource ApplicationContext가 상속받는 것중 MessageSource에 대해서 살펴보자 MessageSource는 메시지 설정 파일을 모아놓고 각 국가에 맞는 메시지를 제공할 수 있다. Spring Boot에서는 ResourceBundleMessageSource가 Bean으로 등록되어 있어 .properties만 설정되어 있으면 메시지를 가져와 사용할 수 있다. messages.properties message_ko_KR.properties message_en_US.properties 등등.. //messages.properties greeting=Hello, my name is {0} //message_ko_KR.proper..
ApplicationContext extends EnvironmentCapable. 프로파일 ApplicationContext 상속받는 것중 EnvironmentCapable에 대해서 살펴보자 프로파일 기능이란, 운영을 유지보수하면서 추가적인 요구사항에서 대해 배포를 진행하게 된다면, 단계적인(local, test, stage) 서버 배포 후 최종적으로 테스트가 완료되면 운영(prd) 서버에 배포하게 된다. 이 때, 각 서버마다 필요로 하는 Bean과 특정 환경에서만 Bean을 등록해야하는 경우, 또는 접근 URL을 다르게 하는 경우를 구별하기 위해 사용하는 것이 프로파일이다. 프로파일 정의해보자 프로파일 정의하는 방법을 소스를 통해 살펴보자 (총 두가지 방법이 있다.) //1. Configuration..
Bean의 Scope Bean의 Scope 싱글톤 싱글톤이란 같은 타입의 객체를 여러개 생성해도 같은 동일한 객체가 생성되는 것이다. 즉, 하나의 객체만이 생성되는 것을 말한다. 기본적으로 Bean은 싱글톤 Scope으로 되어있다. 프로토타입 프로토타입이란 같은 타입의 객체를 여러개 생성할 시 각각 새로운 객체가 생성되는 것이다. 프로토타입 Scope로 지정하고 싶다면 해당 객체에 @Scope("prototype")을 지정해주면 된다. Request Session WebSocket 싱글톤과 프로토타입을 섞어서 쓴다면 문제가 발생하지 않을까? 프로토타입 객체에서 싱글톤 타입을 사용한다면은 문제가 발생하지 않을 것이다. @Component @Scope("prototype") public class Proto..
@Component와 컴포넌트 스캔 컴포넌트 스캔의 주요 기능 스캔하고자 하는 위치를 설정할 수 있다. 즉, 어디서부터 어디까지 스캔할 것인지를 설정하는 것이다. @filter를 사용하여 어떤 어노테이션을 스캔할 건지 아니면 안 할건지를 정할 수 있다. @SpringBootApplication @SpringBootApplication이 위치한 패키지 안에 있는 것들만 스캔한다. 즉, 해당 패키지 안에 있는 것들만 Bean으로 등록할 수가 있다. @filter 현재 @SpringBootApplication은 TyeExcludeFilter.class와 AutoconfigurationExcludeFilter.class를 Bean등록에 제한하고 있다. 기본적으로 스캔되는 어노테이션 @Component에 해당하는..
@Autowired 필요한 의존 객체의 "타입"에 해당하는 Bean을 IoC 컨테이너에서 찾아 주입하는 것이다. @Autowired를 사용할 수 있는 위치는 총 세가지 있다 생성자, setter, field 생성자에 붙여서 사용하는 것 부터 살펴보자 //CustService 객체 @Service public class CustService { CustRepository custRepository; @Autowired public CustService(CustRepository custRepository) { this.custRepository = custRepository } } //CustRepoistory 객체 @Repository //@Repository를 붙이는 이유는 @Repository가 붙여..
Application Context와 여러 Bean 설정 방법 Application Context는 빈들을 설정하고 어디에 의존성을 주입할 건지를 정의하는 것이다. 빈을 설정하는 방법들을 살펴보자 첫번째로는 xml을 사용하는 방식이다. 그 후 main에서 ApplicationContext를 활용해서 빈을 가져와 사용하면 된다. (의존성 주입) public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("application.xml"); String [] beanDefinitionNames = context.getBeanDefinitionNames(); System.out.pri..
- Total
- Today
- Yesterday
- ifPresent
- mustache
- 복사 팩토리
- Effective Java
- 이펙티브 자바
- 빈 순환 참조
- springboot
- Spring
- 김영한
- 자바8
- try with resources
- 점층적 생성 패턴
- flatMap
- 인프런
- 빌더 패턴
- 정적팩터리메서드
- 연관관계
- 생성자
- java8
- JPA
- jdk버전
- package-private
- try catch finally
- @Lazy
- 팩토리 메소드 패턴
- effectivejava
- java
- 스프링부트
- junit
- 이펙티브자바
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |