Results 1 to 4 of 4

Thread: SOS!Why spring-mongodb does not work for creating repository proxy automatically?

  1. #1
    Join Date
    Aug 2010
    Location
    BeiJing
    Posts
    13

    Exclamation SOS!Why spring-mongodb does not work for creating repository proxy automatically?

    Hi all ,I'm new to spring-data-mongodb.
    With reading the document spring-data-document-reference.pdf,I follow its instruction to do some test.
    First, I create a interface which extends PagingAndSortingRepository as following:
    -----------------------------------------------------------------------------
    package cn.knet.mongodb.repository;

    import java.util.List;

    import org.springframework.data.repository.PagingAndSorti ngRepository;

    public interface PersonRepository extends PagingAndSortingRepository<Person, Long> {

    }
    ------------------------------------------------------------------------------
    Second I use the mongodb namespace to config beans in the applicatonContext.xml, as following:
    -------------------------------------------------------------------------------------------------------
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:mongo="http://www.springframework.org/schema/data/mongo"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-3.0.xsd
    http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd">

    <mongo:mongo id="mongo"/>

    <bean id="mongoTemplate" class="org.springframework.data.document.mongodb.M ongoTemplate">
    <constructor-arg ref="mongo"/>
    <constructor-arg value="myndb"></constructor-arg>
    </bean>

    <mongo:repositories base-package="cn.knet.mongodb" mongo-template-ref="mongoTemplate"/>

    </beans>
    -------------------------------------------------------------------------------------------------
    At last the main class is as following:

    public class Main {

    /**
    * @param args
    */
    public static void main(String[] args) {
    ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext .xml");
    for(String name : ac.getBeanDefinitionNames()){
    System.out.println(name);
    }
    ac.getBean("personRepository");
    }

    }
    --------------------------------------------------------------------------------------------------------
    When running, the following exception is thrown:

    Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefini tionException: No bean named 'personRepository' is defined.

    I donot know what's wrong, I just followed the instruction but it didnot work.
    SOS!

  2. #2

    Default

    try

    ac.getBean(PersonRepository.class);

    because you actually don't know the id of the repository

  3. #3
    Join Date
    Aug 2010
    Location
    BeiJing
    Posts
    13

    Default

    It does not work too.
    At last,I found that interfaces which need to be create proxy automatically by spring must extend MongoRepository interface,
    not PagingAndSortingRepository that document mentioned !

  4. #4
    Join Date
    Apr 2006
    Location
    Dresden, Germany
    Posts
    493

    Default

    With M2 that is correct. Please make sure you are using a current milestone (or even snapshot perhaps) until we're going GA as we're continuously fixing bugs.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •