Chyba pri vytváraní bean s názvom "commandGateway" definované v triede cesta zdrojov [org/axonframework/springboot/autoconfig/AxonAutoConfiguration.class]

0

Otázka

Než som sa pridal spring-data-start-jpa a h2-database závislostí, bolo hádzanie tieto chyby. Ja povolené Axon auto-konfiguráciu do jeho vec.

Tu je trasovanie zásobníka som dostal:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'postProductsController': Unsatisfied dependency expressed through method 'setCommandGateway' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'commandGateway' defined in class path resource [org/axonframework/springboot/autoconfig/AxonAutoConfiguration.class]: Unsatisfied dependency expressed through method 'commandGateway' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'axonServerCommandBus' defined in class path resource [org/axonframework/springboot/autoconfig/AxonServerAutoConfiguration.class]: Unsatisfied dependency expressed through method 'axonServerCommandBus' parameter 2; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'commandBus' defined in class path resource [org/axonframework/springboot/autoconfig/AxonAutoConfiguration.class]: Unsatisfied dependency expressed through method 'commandBus' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.axonframework.spring.config.AxonConfiguration': Cannot resolve reference to bean 'org.axonframework.config.Configurer' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'org.axonframework.config.Configurer': Requested bean is currently in creation: Is there an unresolvable circular reference?
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.resolveMethodArguments(AutowiredAnnotationBeanPostProcessor.java:767) ~[spring-beans-5.3.13.jar:5.3.13]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:719) ~[spring-beans-5.3.13.jar:5.3.13]
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119) ~[spring-beans-5.3.13.jar:5.3.13]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) ~[spring-beans-5.3.13.jar:5.3.13]
    at 
    ... 77 common frames omitted

Tu je ukážka radič som sa vytvorili:

@RestController
@RequestMapping(path = "/api/v1/products")
public class PostProductsController {

    private  CommandGateway commandGateway;

    @Autowired
    public void setCommandGateway(CommandGateway commandGateway) {
        this.commandGateway = commandGateway;
    }

    @PostMapping
    public String createProduct(@RequestBody CreateProductRestModel createProductRestModel){

        CreateProductCommand createProductCommand = CreateProductCommand.builder()
                .price(createProductRestModel.getPrice())
                .quantity(createProductRestModel.getQuantity())
                .title(createProductRestModel.getTitle())
                .productId(UUID.randomUUID().toString())
                .build();

        String returnValue;

        try{
            returnValue = commandGateway.sendAndWait(createProductCommand);
        } catch (Exception e){
            returnValue = e.getLocalizedMessage();
        }
        return returnValue;
    }
}

Potom, čo som pridal závislostí, začalo hádzať tieto chyby:

org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'entityManagerFactory': Requested bean is currently in creation: Is there an unresolvable circular reference?
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.beforeSingletonCreation(DefaultSingletonBeanRegistry.java:355) ~[spring-beans-5.3.13.jar:5.3.13]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:227) ~[spring-beans-5.3.13.jar:5.3.13]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.13.jar:5.3.13]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.13.jar:5.3.13]
    at org.springframework.beans.factory.support.AbstractBeanFactory.isSingleton(AbstractBeanFactory.java:463) ~[spring-beans-5.3.13.jar:5.3.13]
    at org.axonframework.spring.config.AbstractAnnotationHandlerBeanPostProcessor.postProcessAfterInitialization(AbstractAnnotationHandlerBeanPostProcessor.java:73) ~[axon-spring-4.5.4.jar:4.5.4]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:455) ~[spring-beans-5.3.13.jar:5.3.13]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1808) ~[spring-beans-5.3.13.jar:5.3.13]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-beans-5.3.13.jar:5.3.13]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.13.jar:5.3.13]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.13.jar:5.3.13]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.13.jar:5.3.13]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.13.jar:5.3.13]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.13.jar:5.3.13]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1154) ~[spring-context-5.3.13.jar:5.3.13]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:908) ~[spring-context-5.3.13.jar:5.3.13]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.13.jar:5.3.13]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.0.jar:2.6.0]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730) ~[spring-boot-2.6.0.jar:2.6.0]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) ~[spring-boot-2.6.0.jar:2.6.0]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:302) ~[spring-boot-2.6.0.jar:2.6.0]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[spring-boot-2.6.0.jar:2.6.0]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1290) ~[spring-boot-2.6.0.jar:2.6.0]
    at com.mrdiipo.productsservice.ProductsServiceApplication.main(ProductsServiceApplication.java:12) ~[classes/:na]

A tu je moja application.properties súbor:

server.port = 0

spring.application.name=products-service
eureka.client.service-url.defaultZone= http://localhost:8761/eureka
eureka.instance.instanceid=${spring.application.name}:${instanceId:${random.value}}

spring.datasource.url=jdbc:h2:file:~/products;AUTO_SERVER=true
spring.datasource.username=root
spring.datasource.password=XXXXX
spring.datasource.driver-class-name=org.h2.Driver
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=update
spring.h2.console.enabled=true

spring.datasource.generate-unique-name= false
spring.h2.console.path=/h2-console

spring.h2.console.settings.web-allow-others=true
axon cqrs saga spring-boot
2021-11-22 20:09:38
2

Najlepšiu odpoveď

3

Najdôležitejšie vedieť, tu je to, ktorá verzia Jar Boot používate, ktoré som mohol vidieť z stacktrace: 2.6.0.

Táto verzia, vydal niekde tento týždeň, pridaná dodatočná kontrola, ktorá môže vysvetliť, čo ste sa stretli a možno nájsť tu.

Cituje nich:

Kruhový Odkazy Zakázané Štandardne

Kruhový odkazy medzi zrná sú teraz zakázané v predvolenom nastavení. Ak aplikácia zlyhá spustiť kvôli BeanCurrentlyInCreationException dôrazne odporúčame, aby ste aktualizovať konfiguráciu prelomiť závislosť cyklu. Ak ste schopní urobiť tak, kruhové odkazy môžu byť povolený znovu nastavenie jar.hlavné.povoliť-circular-odkazy na pravdivé, alebo pomocou nových setter metódy na SpringApplication a SpringApplicationBuilder To bude obnovenie 2.5 správanie a automaticky pokúsi prelomiť závislosť cyklu.

Z Axon strane, sme sa už pracujeme na tom a vy PR opraviť tento problém môžete nájsť tu. Po, ktoré je zlúčené, môžete očakávať, že menšie vydanie, to opraviť, ale pokojne sledovať Jar je radiť o tom, ako vyriešiť sami, ak budete potrebovať.

KR,

2021-12-20 14:12:21

Woow!! Fungovalo to ako kúzlo po hodinách ladenie. Sledoval som na jar poradenstvo. Pridala som aj "na jar.hlavné.povoliť-circular-ref=true" na moju žiadosť.vlastnosti súboru. Ďakujem vám, pane.
Elegbede Yusuf Oladipupo
0

Otázka nie je zrozumiteľné, prosím, zdieľať viac kódu sa s nami dostať detail odpovede. Vyzerá to, že vaše dve triedy je dôležitý. Ako mdh spomenul v komentároch, @Lenivý môže vyriešiť váš problém.

@Autowired @Lazy
private Class class;

Pre viac informácií: https://www.baeldung.com/circular-dependencies-in-spring

2021-11-23 09:48:36

Veľmi vám ďakujem, pane. Ak chcete byť úprimný, chyba je trochu prekvapujúce. Táto chyba sa začal, keď som pridal jar-data-jpa a h2-databáza. Než som sa pripočítajú závislostí, bolo hádzanie chybu z axon commandGateway. Chcel by som dodať, chyby z axon čoskoro.
Elegbede Yusuf Oladipupo

V iných jazykoch

Táto stránka je v iných jazykoch

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................