2012-12-19 2 views
2

다중 모듈 Maven 3 프로젝트에서 MongoDB 용 스프링 데이터를 사용하여 첫 번째 Java 애플리케이션을 설정하려고합니다. 여기에 해당 버전은 다음과 같습니다맞춤 저장소 인터페이스의 오류

  • 자바 7
  • MongoDB를-는 Win32-x86_64-2.2.0
  • 봄 데이터 1.1.1.RELEASE
  • 봄 3.2.0.RELEASE

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'actorFacade': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private es.mi.casetools.praetor.persistence.springdata.repositories.ActorRepository es.mi.casetools.praetor.facade.impl.DefaultActorFacade.actorRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'actorRepository': FactoryBean threw exception on object creation; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property insert found for type void 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) 
    at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:106) 
    at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:57) 
    at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:100) 
    at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:248) 
    at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:124) 
    at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:148) 
    ... 30 more 

:

나는 다음과 같은 런타임 오류를 받고 있어요

Google에서 검색 나는 같은 문제가있는 사용자를 발견했으며 사용자 지정 리포지토리와 관련이있는 것 같습니다.

여기는 몽고 문서로 저장하려는 개체입니다.

public class Actor { 
    public enum ActorStereotype { 
     SYSTEM, 
     PERSON 
    } 
     private String id; 
    private String code; // unique 
    private ActorStereotype stereotype; 
    private String title; // Short title for the actor 
    private String description; 
    private String projectId; // project this actor belongs to 

     // getters & setters 

표준 저장소 인터페이스입니다.

public interface ActorRepository extends MongoRepository<Actor, String>, ActorRepositoryCustom { 
} 

사용자 인터페이스 (여기서는 오류가 있다고 생각합니다).

@NoRepositoryBean 
public interface ActorRepositoryCustom { 
    void updateSingleActor(Actor actor); 
    void insertActor(Actor actor); 
} 

맞춤 인터페이스 구현.

public class ActorRepositoryCustomImpl implements ActorRepositoryCustom { 
    @Autowired 
    private MongoTemplate mongoTemplate; 

    @Override 
    public void updateSingleActor(Actor actor) { 
     if(actor.getId() != null) 
      throw new MissingIdException(); 

     // TODO change to Spring Converter 
     DBObject dbo = (DBObject)mongoTemplate.getConverter().convertToMongoType(actor); 

     mongoTemplate.updateFirst(query(where("_id").is(actor.getId())), 
       Update.fromDBObject(dbo, new String[]{}), 
       Actor.class); 
    } 

    @Override 
    public void insertActor(Actor actor) { 
     if(actor.getId() != null) 
      throw new IdProvidedException(); 

     mongoTemplate.save(actor); 
    } 

} 

그리고 마지막으로 응용 프로그램 컨텍스트.

<context:annotation-config/> 

    <bean id="propertyConfigurer"  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
     <property name="locations"> 
      <list> 
       <value>classpath:properties/test.properties</value> 
      </list> 
     </property> 
    </bean> 

    <!-- mongodb configuration -->   
    <mongo:repositories base-package="es.mi.casetools.praetor.persistence.springdata.repositories" 
     mongo-template-ref="mongoTemplate" repository-impl-postfix="Impl">     
     <repository:exclude-filter type="annotation" expression="org.springframework.data.repository.NoRepositoryBean"/>  
    </mongo:repositories> 

    <mongo:mongo id="mongotest" host="${mongo.host}" port="${mongo.port}" write-concern="SAFE"> 
    </mongo:mongo> 

    <mongo:db-factory dbname="${mongo.dbname}" mongo-ref="mongotest"/> 

    <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> 
     <constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/> 
    </bean> 
    <bean id="actorFacade" class="es.mi.casetools.praetor.facade.impl.DefaultActorFacade"> 
    </bean> 

</beans> 

위의 응용 프로그램 컨텍스트를로드하는 데 실패한 작은 스프링 테스트가 있습니다. 예외를 지정하면 맨 위에 표시됩니다.

다음을 추가하려고했지만 동일한 예외가 발생합니다.

<bean id="actorRepositoryCustomImpl" class="es.mi.casetools.praetor.persistence.springdata.repositories.ActorRepositoryCustomImpl"></bean> 

누군가가 오류의 원인을 알 수 있습니까?

+1

커스텀 리포지 (custom repos)도 사용하고있어 아무런 문제가 없었습니다. 차이점은 내 봄 구성에서는 repository-impl-postfix 속성의 값이 CustomImpl이라는 점입니다. 그것을 시도하십시오! –

답변

2

Miguel의 의견으로 문제가 해결되었습니다. 나는 구현 클래스에 잘못된 이름을 부여했다. 비슷한 질문을 한 번 봤기 때문에 다른 사람에게 도움이 될 수있는 희망으로 솔루션을 명확히하려고 노력할 것입니다.

나는

public interface ActorRepository extends MongoRepository<Actor, String>, ActorRepositoryCustom 

사용자 정의 인터페이스 정의는 다음과 같습니다 다음과 같은 인터페이스 정의가 :

public interface ActorRepositoryCustom 

그래서 내 오류가 Springdata 픽업 것이 기대 ActorRepositoryCustomImplActorRepositoryCustom의 구현을 명명 된 그 후위 (postfix)로서의 구현은 디폴트의 것 Impl입니다. 것은, 구현하고있는 것이 ActorRepositoryCustom이더라도, Springdata는 기본적으로 ActorRepositoryImpl을 찾습니다. 해결책은 선택 속성 repository-impl-postfix을 사용하고 CustomImpl으로 설정합니다.