본문 바로가기
JPA/Annotation

@EntityScan

by BAYABA 2021. 9. 27.
  1. 개인 공부 목적으로 작성한 글입니다.
  2. 아래 출처를 참고하여 작성하였습니다.

목차

  1. @EntityScan 이란?
  2. Sample Code

1. @EntityScan 이란?

  1. @EntityScan은 Entity 클래스가, Entity를 사용하고자 하는 application main package와 전혀 다른 package에 있을 때 사용합니다.
  • 즉, Entity Class가 main application package나 그 하위 패키지에 있지 않을 경우
  1. application이, 전혀 다른 패키지에 있는 Entity Class를 찾을 수 있도록 해주는 어노테이션입니다.
  • 즉, Spring에게 우리 애플리케이션에서 사용되는 엔티티를 찾을 위치를 알려줍니다.
  1. 아래 샘플 코드처럼 별도로 basePackages 속성을 주지 않으면 @SpringBootApplication에 설정한 빈 scan 범위와 동일한 범위로 Entity를 scan 합니다.

2. Sample Code

@EntityScan(basePackages = {"com.example.domainmodel"})
@SpringBootApplication
public class ReactiveAppApplication {

    public static void main(String[] args) {
        SpringApplication.run(ReactiveAppApplication.class, args);
    }

}

출처

  1. Spring @EntityScan vs. @ComponentScan
  2. nested exception is java.lang.IllegalArgumentException: Not a managed type: class
  3. Creating a Multi Module Project

'JPA > Annotation' 카테고리의 다른 글

@PersistenceContext  (0) 2021.10.13
@MappedSuperclass  (0) 2021.10.10
@JoinColumn  (0) 2021.10.06
@EnableJpaRepositories  (0) 2021.09.27