gradle 无法自动连接,未找到...类型的Bean,外部jar反编译了.class文件

2vuwiymt  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(115)

我在启动我的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

fd3cxomn

fd3cxomn1#

您需要创建一个用@Bean注解的方法,该方法返回EventSourcingServiceFactory类型的instace
或者创建另一个类来扩展EventSourcingServiceFactory类,你需要用@Bean来命名它,这样spring在自动装配时就可以在上下文中找到它。
范例:

@Bean
public Class EventSourcingServiceFactory2 extends EventSourcingServiceFactory {
}

字符串

相关问题