【发布时间】:2014-04-22 16:00:39
【问题描述】:
我尝试自动装配我的自定义 mongo 存储库(并且似乎执行了构造函数)但结果仍然为 null
我看过一些类似的问题 Spring Data Neo4j - @Autowired Repository == null 和 spring data mongo repository is null
但我仍然不知道如何解决这个问题。
public class TestRepo {
@Autowired
PersonRepository repository;
public void find(String name)
{
System.out.println(repository.findByName(name));
}
}
配置
<mongo:repositories base-package="com.yyyy.zzz" />
PersonRepository
public interface PersonRepository extends Repository<Person, BigInteger> {
@Query("{name : ?0}")
public Person findByName(String name);
}
实施
public class PersonRepositoryImpl implements PersonRepository{
PersonRepositoryImpl()
{
System.out.println("constructing");
}
public Person findByName(String name) {
...
}
}
如果我直接从上下文中获取存储库 bean,它就可以工作
【问题讨论】:
标签: mongodb repository spring-data