프로그래밍/Spring

[Spring] SpringFramework Configuration, 각종 스프링 관련 면접 질문

Jay Tech 2018. 11. 12. 10:52
반응형

Spring Bean Scope


스프링 빈에는 Scope를 정의할 수 있다.


singleton : 싱글톤 스코프, 별도지정이 없으면 default로 들어가게 된다. 멀티 스레드환경에서 동시 접근이 발생하므로 상태 관리가 중요하다.


prototype : 요청마다 새 bean instance를 생성한다. 멀티 스레드 환경에서 singleton보다 관리가 수월하다.


request : single instance per http request.


session : single instance per http session.



[질문 목록]


* 스프링의 configuration option 은?

XML, Annotations, Java, Groovy, DSL


* SOLID 의 S 의 기능?

Single Responsibility Principle


* SpringFramework 5에서는 XML Configuration이 아직 지원된다.


* Dependency Injection은 생성자 방식을 지향하는이유는?

클래스가 초기화 되었을 때 의존성을 주입하기 위해서이다.


* ComponentScan이 어떤 Annotation을 스캔하는지?

Spring's Stereotype annotation 을 scan한다. @Controller, @Service, @Component, @Repository


* Java class를 Spring configuration으로 쓰려면 어떤 annotation을 쓰는지?

@Configuration


* Java configuration class 안에 어떻게 spring component를 정의하는지?

@Bean 


* 2개의 bean (같은 타입)이 있는데 어떻게 한쪽의 preference를 갖게 하는지?

@Primary annoation이 primary bean을 설정한다.


* Spring Bean의 lifecycle에 접근하는 2가지 annotation은?

@PostConstruct, @PreDestory


* @RestController가 Spring StereoType인가?

기술적으로, @Controller와 @ResponseBody 를 합치기 위한 편리한 annoation이다.


* SpringBoot Maven project가 왜 Spring Boot Parent POM을 상속받는지?

Compatible하게 하기 위해서


* Spring Sterotype이 어떤 annoation을 상속하는지?

@Component


* Ant로 Spring Boot을 빌드할 수 있는지?

가능, Ivy 사용해야함


* Spring Boot Starter 가 무엇인가?

Spring Boot Starter는 POM으로써 dependency들의 공통 집합이다. (기본 설정같은 것) 대부분 자바 프로젝트에 가능하다.


* @Repository의 특별한 점?

DAO관련 특정 예외를 잡을 수 있다 = 스프링이 specific persistence exception을 잡는다. (persistence는 영속성을 의미한다.) 그리고 Spring exception으로 다시 던져준다.


* @SpringBootApplication은 3가지의 다른 annotation들을 가지고 있다. 무엇인가?

@Configuration, @EnableAutoConfiguration, @ComponentScan


* auto-configuration을 springboot에서 어떻게 실행하는지?

Start Spring Boot에서 커맨드라인에 --debug를 한다.


* 특정 auto-configuration 클래스를 disable할 수 있는가?

@EnableAutoConfiguration안에 exclude 인자를 넣어준다.


* Spring scope의 default는 무엇인가?

Singleton Scope 이다.


* custom bean scope를 생성할 수 있는가?

가능하다. (extensible하니까)


* Prototpye에는 bean이 어떻게 생겅되는가?

매 요청 마다 새로운 bean instance를 생성한다.

반응형