Par*_*aum 3 spring dependency-injection reactive-programming kotlin spring-boot
问题:
我有一个ReactiveCrudRepository
我想在 a 中使用的,RestController
但 Spring 没有发现它再被注入。在我将存储库重构为响应式CrudRepository
之前(它是之前的),存储库是由 Spring 找到并注入的。
现在我收到这个错误:
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in de.shinythings.microservices.core.product.services.ProductServiceImpl required a bean of type 'de.shinythings.microservices.core.product.persistence.ProductRepository' that could not be found.
Action:
Consider defining a bean of type 'de.shinythings.microservices.core.product.persistence.ProductRepository' in your configuration.
Run Code Online (Sandbox Code Playgroud)
存储库如下所示: 链接到 GitHub
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in de.shinythings.microservices.core.product.services.ProductServiceImpl required a bean of type 'de.shinythings.microservices.core.product.persistence.ProductRepository' that could not be found.
Action:
Consider defining a bean of type 'de.shinythings.microservices.core.product.persistence.ProductRepository' in your configuration.
Run Code Online (Sandbox Code Playgroud)
其余控制器如下所示: 链接到 GitHub
interface ProductRepository : ReactiveCrudRepository<ProductEntity, String> {
fun findByProductId(productId: Int): Mono<ProductEntity>
}
Run Code Online (Sandbox Code Playgroud)
到目前为止我尝试过的:
我启用了我的debug
标志以application.yml
从输出中了解更多信息,但这并没有产生有用的见解。
我ProductRepository
从ProductServiceImpl
类中删除了依赖项,以便在启动 Spring 时不会出现上述错误。
然后,我写我自己一个小测试来询问ApplicationContext
的ProductRepository
具体做法是:
@SpringBootTest
class BeanLoadingDebugging {
@Autowired
private lateinit var applicationContext: ApplicationContext
@Test
fun test() {
val bean = applicationContext.getBean(ProductRepository::class.java)
Assert.notNull(bean, "Bean not found!")
}
}
Run Code Online (Sandbox Code Playgroud)
这也行不通!
所以看起来这个存储库只是不想被发现。我仔细检查了这个并尝试了同样的非反应性CrudRepository
,发现了这一点。???
全面披露:
我是 Spring / Spring Boot 的新手,很高兴在这里提供任何建议。
小智 5
首先,您必须将依赖项从 更新org.springframework.boot:spring-boot-starter-data-mongodb
为org.springframework.boot:spring-boot-starter-data-mongodb-reactive
。
其次,启用如下所示的反应式支持,
@SpringBootApplication
@ComponentScan("de.shinythings")
@EnableReactiveMongoRepositories
class RecommendationServiceApplication
Run Code Online (Sandbox Code Playgroud)
在这两个更改之后,我可以看到测试de.shinythings.microservices.core.recommendation.BeanLoadingDebugging
成功。
深入了解Spring 反应式 mongo
归档时间: |
|
查看次数: |
890 次 |
最近记录: |