본문 바로가기

- Spring

[ERROR] Error creating bean with name 'repositoryController' / At least one JPA metamodel must be present!

반응형

예전에 개발된 API에 신규 개발을 할당받아 실행을 시켰더니 아래와 같은 에러가 발생했습니다.

 

2020:10:16 17:27:55.691 ERROR --- [RMI TCP Connection(2)-127.0.0.1] o.s.boot.SpringApplication : Application startup failed 

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'repositoryController' defined in URL [jar:file:/Users/jang/server/apache-tomcat-7.0.106/webapps/ROOT/WEB-INF/lib/spring-data-rest-webmvc-2.6.9.RELEASE.jar!/org/springframework/data/rest/webmvc/RepositoryController.class]: Unsatisfied dependency expressed through constructor parameter 3; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resourceMappings' defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.rest.core.mapping.RepositoryResourceMappings]: Factory method 'resourceMappings' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'persistentEntities' defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mapping.context.PersistentEntities]: Factory method 'persistentEntities' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: At least one JPA metamodel must be present!

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resourceMappings' defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.rest.core.mapping.RepositoryResourceMappings]: Factory method 'resourceMappings' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'persistentEntities' defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mapping.context.PersistentEntities]: Factory method 'persistentEntities' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: At least one JPA metamodel must be present!

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.rest.core.mapping.RepositoryResourceMappings]: Factory method 'resourceMappings' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'persistentEntities' defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mapping.context.PersistentEntities]: Factory method 'persistentEntities' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: At least one JPA metamodel must be present!

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'persistentEntities' defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mapping.context.PersistentEntities]: Factory method 'persistentEntities' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: At least one JPA metamodel must be present!

 

제가 JPA를 쓰고 있었다면 JPA에 문제가 있구나라고 하겠지만,

이 프로젝트는 jdbc로 구현된 API 입니다.

 

또, 오랜만에 gradle이 아닌 maven을 만나서 헤매기도 했습니다.

pom.xml에서 jpa 관련된 것이 있는지 확인해봤지만, 그런 dependency는 존재하지 않아서 난항을 겪던 중

 

repositoryController 이 녀석이 어디 있는지 따라 들어가 보니

spring-boot-starter-data-rest에 있더군요.

 

버전 종속성 없이 아래와 같이 선언되어 있었습니다.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>

 

개발 당시에는 spring-boot-starter-data-rest에 jpa 설정이 없었으나,

버전이 올라가며 추가된 것으로 추정되어

EnableAutoConfiguration에서 자동 설정이 되지 않도록 제외시켰습니다.

 

@EnableAutoConfiguration (exclude = { JpaRepositoriesAutoConfiguration.class })

 

추가로 EnableAutoConfiguration은 SpringBootApplication에 포함되어 있어,

SpringBootApplication에서 선언할 경우 아래와 같이 사용해야 합니다.

 

@SpringBootApplication(exclude = {JpaRepositoriesAutoConfiguration.class})

반응형