촙촙촙개발자
10
2017-12-11 22:27:09 작성 2017-12-12 15:05:18 수정됨
4
6320

Spring Data Jpa 어노테이션 에러


안녕하세요. 이제 막 일년차된 초보 개발자입니다.

이번에 jpa, hibanate를 접하게되어 책을보고 공부하고 있습니다.

그리고, spring data jpa를 이용하여 프레임워크를 설정 하고있습니다.


프레임워크 스팩은

java 1.8

servlet 3.1

spring 4.3.2.RELEASE

tomcat 8.5

spring-data-jpa 2.0.0.RELEASE

hibernate 5.1.0.Final

위의 스펙으로 진행중입니다.


ServletConfiguration.class

@Configuration										// 자바 기반의 설정임을 알려주는 어노테이션
@EnableWebMvc										// <mvc:annotation-driven>
@ComponentScan(basePackages = "com.knk.spring4")	// <context:componet-scan> 
public class ServletConfiguration extends WebMvcConfigurerAdapter {
........
}


PersistenceConfig.class

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(basePackages = "com.knk.spring4.repository") // 	<jpa:repositories base-package="com.knk.spring4.repository" />
public class PersistenceConfig {
.....
	@Bean(name = "entityManagerFactory")
	public EntityManagerFactory entityMangerFactory() {
		
		logger.info("EntityMangerFactory");
		
		LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
		emf.setPersistenceUnitName("springDataTest");
		emf.setDataSource(getDataSource());	// DB 정보
		emf.setPackagesToScan(new String[] {"com.knk.spring4.entity"});	// Entity 탐색 위치

		JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
		emf.setJpaVendorAdapter(vendorAdapter);	// 하이버네이트 구현체 사용
		emf.setJpaProperties(additionalProperties());	// 하이버네이트 설정
		emf.afterPropertiesSet();
		
		return emf.getObject();
	}
.......
}

MemberEntity.class

@Entity
@Table(name = "MEMBER_KNK")
@SequenceGenerator(name = "MEMBERIDX_SEQ_GENERATOR"
					, sequenceName = "MEMBERIDX_SEQ"
					, initialValue = 1)
public class MemberEntity implements Serializable {
	
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE
					, generator = "MEMBERIDX_SEQ_GENERATOR")
	private long memberIdx;
........
}

MemberRepository.class

@Repository
public interface MemberRepository extends JpaRepository<MemberEntity, Long> {
	
	@Query("select m from MemberVO m where m.id=:id")
	public MemberEntity getMemberIDbyId(@Param("id") String id);
}

MemberService.class

@Service
@Transactional
public class MemberService {

	@Autowired 
	private MemberRepository memberRepository;
........
}

  패키지구조

에러메시지

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'memberController': Unsatisfied dependency expressed through field 'memberService': Error creating bean with name 'memberService': Unsatisfied dependency expressed through field 'memberRepository': Error creating bean with name 'memberRepository': Initialization of bean failed; nested exception is java.lang.AbstractMethodError; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'memberRepository': Initialization of bean failed; nested exception is java.lang.AbstractMethodError; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'memberService': Unsatisfied dependency expressed through field 'memberRepository': Error creating bean with name 'memberRepository': Initialization of bean failed; nested exception is java.lang.AbstractMethodError; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'memberRepository': Initialization of bean failed; nested exception is java.lang.AbstractMethodError
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:569)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:349)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:776)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
	at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668)
	at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:540)
	at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494)
	at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
	at javax.servlet.GenericServlet.init(GenericServlet.java:158)
	at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1183)
	at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:992)
	at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4931)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5241)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:748)
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'memberService': Unsatisfied dependency expressed through field 'memberRepository': Error creating bean with name 'memberRepository': Initialization of bean failed; nested exception is java.lang.AbstractMethodError; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'memberRepository': Initialization of bean failed; nested exception is java.lang.AbstractMethodError
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:569)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:349)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:207)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1214)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1054)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1019)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:566)
	... 28 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'memberRepository': Initialization of bean failed; nested exception is java.lang.AbstractMethodError
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:207)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1214)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1054)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1019)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:566)
	... 42 more
Caused by: java.lang.AbstractMethodError
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:99)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:302)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:129)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1481)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1226)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
	... 52 more


기존 entity, service, repository패키지안에 테스트클래스 파일로만 실행했을때는 이상없이 작동하다가

하위로 패키지를 두고 실해시키니 bean을 못찾는것 같습니다.

PersistenceConfig.class와 ServletConfiguration.class 에서 패키지를 잘못 설정한것 같은데..

계속해서 찾아보면서 하고있지만 고수님들 도움 요청 드립니다.


감사합니다!

0
0
  • 답변 4

  • ksshim86
    1k
    2017-12-11 22:38:55 작성 2017-12-11 22:54:23 수정됨

    ServletConfiguration클래스를 다른 패키지들보다 상위 패키지로 올려보세요.


    jpa 공부하시는거 같아 샘플로 만들어본 프로젝트 링크도 첨부합니다.

    https://github.com/ksshim86/shya/tree/master/ShyaProject

    1
  • 촙촙촙개발자
    10
    2017-12-12 10:48:34

    답변과 샘플 프로젝트 정말로 감사드립니다!


    말씀해주신대로 다른 패키지보다 상단인


    com.knk.spring4에 ServletConfiguration클래스를 옮기고 실행 해보았으나.


    똑같은 현상이 나타났습니다.ㅠㅠ

    0
  • javaing
    2k
    2017-12-13 01:20:13
    stackoverflow에선 spring-orm 버전이 spring-core보다 높아서 비슷한 에러가 났다고 하네요. 디펜던시에서 버전들 확인해보세요
    1
  • 촙촙촙개발자
    10
    2017-12-13 11:29:51

    javaing님 답변 정말 감사합니다.

    spring-data-jpa 2버전은 spring-core 5부터 호환이 된다고 하네요 ..ㅠㅠ

    버전을 낮추니까 해결됐습니다!

    감사합니다~!!

    0
  • 로그인을 하시면 답변을 등록할 수 있습니다.