我有一个预计登记到GitHub这里https://github.com/romeoopk/demo请注意,这不是一个“完整”的工作项目,但正在进行中!
我有两个数据源(h2 mem DB和Cassandra)。该项目的目的是隐藏服务背后的实现。
我正在反对两个配置文件
开发 - 反对h2
测试 - 反对卡桑德拉
当我对测试运行时,它运行正常,但是当我对开发运行时,我得到以下消息
com.example.demo.service.H2HotelServiceImpl中构造函数的参数0需要一个无法找到的类型为“com.example.demo.repository.HotelRepository”的bean。
行动:
考虑在配置中定义'com.example.demo.repository.HotelRepository'类型的bean。
我不确定,如何正确注入,以便H2HotelRepository和H2HotelByLetterRepository用于查询H2
任何帮助都非常感谢!!!
您在cassandra文件夹下的存储库类是这样的
@Repository
@Profile("test")
public class CassandraHotelRepository implements HotelRepository<Hotel> {
....
}
@Repository
@Profile("test")
public class CassandraHotelByLetterRepository implements HotelByLetterRepository<HotelByLetter, HotelByLetterKey> {
....
}
但是在你的h2文件夹中你声明为
@Repository
@Profile("dev")
public abstract class H2HotelRepository implements CrudRepository<Hotel, String>, HotelRepository<Hotel> {
...
}
@Repository
@Profile("dev")
public abstract class H2HotelByLetterRepository implements CrudRepository<HotelByLetter, HotelByLetterKey>, HotelByLetterRepository<HotelByLetter, HotelByLetterKey> {
.....
}
正如你可以在h2文件夹中清楚地看到的那样,即对于profile dev,没有具体的类。你在h2下的两个存储库都是abstract
。
删除摘要,它应该工作正常。