我在启动我的SpringBootApplication时遇到了一个问题。我是Spring的新手,已经查看了StackOverflow上的现有问题,但它们对我没有帮助。
我有一个EventSourcingConfig
,其中EventSourcingServiceFactory
声明为@Autowired
。
package com.cinephilia.review.config
import com.cinephilia.review.aggregates.CommentAggregate
import com.cinephilia.review.aggregates.CommentAggregateState
import com.cinephilia.review.aggregates.RatingAggregate
import com.cinephilia.review.aggregates.RatingAggregateState
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import ru.quipy.core.EventSourcingServiceFactory
import java.util.*
@Configuration
class EventSourcingConfig {
@Autowired
private lateinit var eventSourcingServiceFactory: EventSourcingServiceFactory
@Bean
open fun commentService() = eventSourcingServiceFactory.create<UUID, CommentAggregate, CommentAggregateState>()
@Bean
open fun ratingService() = eventSourcingServiceFactory.create<UUID, RatingAggregate, RatingAggregateState>()
}
字符串
这是我的应用程序的外部依赖项,它在我的build.gradle.kts
中声明
dependencies {
...
implementation("ru.quipy:tiny-event-sourcing-spring-boot-starter:2.3.0")
...
}
型
我可以 * Ctrl+单击 * 到EventSourcingServiceFactory
并转到实现EventSourcingServiceFactory
。
// IntelliJ API Decompiler stub source generated from a class file
// Implementation of methods is not available
package ru.quipy.core
public final class EventSourcingServiceFactory public constructor(aggregateRegistry: ru.quipy.core.AggregateRegistry, eventMapper: ru.quipy.mapper.EventMapper, eventStore: ru.quipy.database.EventStore, eventSourcingProperties: ru.quipy.core.EventSourcingProperties) {
public final val aggregateRegistry: ru.quipy.core.AggregateRegistry /* compiled code */
public final val eventMapper: ru.quipy.mapper.EventMapper /* compiled code */
public final val eventSourcingProperties: ru.quipy.core.EventSourcingProperties /* compiled code */
public final val eventStore: ru.quipy.database.EventStore /* compiled code */
public final inline fun <ID : kotlin.Any, reified A : ru.quipy.domain.Aggregate, S : ru.quipy.domain.AggregateState<ID, A>> create(): ru.quipy.core.EventSourcingService<ID, A, S> { /* compiled code */ }
}
型
所以当我尝试用gradle bootRun
启动我的应用程序时,它无法启动并出错。
***************************
APPLICATION FAILED TO START
***************************
Description:
Field eventSourcingServiceFactory in com.cinephilia.review.config.EventSourcingConfig required a bean of type 'ru.quipy.core.EventSourcingServiceFactory' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'ru.quipy.core.EventSourcingServiceFactory' in your configuration.
型
那么我该如何解决这个问题呢?设置@ComponentScan
和@EnableAutoconfiguration
并没有帮助我。我认为这个问题是EventSourcingServiceFactory
没有被anotated。但是我怎么能做到这一点,当它是我的应用程序的外部依赖,我只有它的jar文件。
我尝试为SpringBoot应用程序设置@ComponentScan
和@EnableAutoConfiguration
1条答案
按热度按时间fd3cxomn1#
您需要创建一个用@Bean注解的方法,该方法返回
EventSourcingServiceFactory
类型的instace或者创建另一个类来扩展
EventSourcingServiceFactory
类,你需要用@Bean
来命名它,这样spring在自动装配时就可以在上下文中找到它。范例:
字符串