-
Aug 26th, 2011, 01:23 AM
#1
SOS:Why I cannot get the bean named personRepository?
Hi, I do those steps by following spring-data-document-reference.pdf which said using the mongo:repositories namespace to automatically create the repository for us.
I define a interface PersonRepository as follwing:
package cn.knet.mongodb.repository;
import java.util.List;
import org.springframework.data.repository.PagingAndSorti ngRepository;
public interface PersonRepository extends PagingAndSortingRepository<Person, Long> {
}
And applicationContext.xml:
<?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>
The main class is:
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 I start the application , 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!
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
-
Forum Rules