Law
December 21, 2022, 3:05pm
1
I have this error that has made me not advance in the CQRS implementation in spring boot.
Err: Parameter 0 of constructor in com.lawrence.digitalbanking.command.controller.AccountCommandRestAPI required a bean of type ‘org.axonframework.commandhandling.gateway.CommandGateway’ that could not be found.
Here is my class code
@RestController
@RequestMapping("/commands/accounts")
@Slf4j
@AllArgsConstructor
public class AccountCommandRestAPI {
private CommandGateway commandGateway;
@PostMapping("/create")
public CompletableFuture<String> newAccount(@RequestBody CreateAccountRequestDTO request) {
log.info("CreateAccountRequestDTO =>"+request.getInitialBalance().toString());
CompletableFuture<String> resp = commandGateway.send(new createAccountCommand(
UUID.randomUUID().toString(),
request.getInitialBalance(),
request.getCurrency()
));
return resp;
}
}
This is my pom.xml dependency
<dependency>
<groupId>org.axonframework</groupId>
<artifactId>axon-spring-boot-starter</artifactId>
<version>4.6.2</version>
<exclusions>
<exclusion>
<groupId>org.axonframework</groupId>
<artifactId>axon-server-connector</artifactId>
</exclusion>
</exclusions>
</dependency>
I don’t really know what I am missing. I have tried several times. My CommandGateway is not getting injected.
Please thanks in Advance.
I was expecting it to run but it throws that error despite the dependency being included in the pom.xml
Gerard
(Gerard Klijs)
December 21, 2022, 4:29pm
2
By excluding the axon-server-connector
it seems like you don’t want to use Axon Server.
You likely want to use a distributed command gateway, and thus distributed command bus through. For that you need one of two extensions, and set a property to disable the auto wiring for Axon Server. You can get the details from the reference guide .
Please let is know if that helped to get it working.
Law
December 21, 2022, 4:51pm
3
Thank you for answering. I just removed the exclusion part and it stills throw the same error
Law
December 21, 2022, 4:52pm
4
I just started the axon server too
java -jar AxonServer.jar
Law
December 21, 2022, 4:53pm
5
@Gerard please looking forward to resolving this problem once and for all. It has really hindered my progress.
Law
December 21, 2022, 4:54pm
6
My full pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.lawrence</groupId>
<artifactId>digital-banking</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>digital-banking</name>
<description>digital banking</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.axonframework</groupId>
<artifactId>axon-spring-boot-starter</artifactId>
<version>4.6.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Law
December 21, 2022, 4:57pm
7
then I injected it here
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import org.axonframework.commandhandling.gateway.CommandGateway;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lawrence.digitalbanking.command.dto.CreateAccountRequestDTO;
import com.lawrence.digitalbanking.coreapi.commands.createAccountCommand;
import lombok.extern.slf4j.Slf4j;
@RestController
@RequestMapping("/commands/accounts")
@Slf4j
public class AccountCommandRestAPI {
private CommandGateway commandGateway;
public AccountCommandRestAPI(CommandGateway commandGateway) {
this.commandGateway=commandGateway;
}
@PostMapping("/create")
public CompletableFuture<String> newAccount(@RequestBody CreateAccountRequestDTO request) {
log.info("CreateAccountRequestDTO =>"+request.getInitialBalance().toString());
CompletableFuture<String> resp =
commandGateway.send(new createAccountCommand(UUID.randomUUID().toString(),
request.getInitialBalance(),
request.getCurrency()));
return resp;
}
}
Gerard
(Gerard Klijs)
December 21, 2022, 5:27pm
8
Axon Framework is not Spring Boot 3 compatible yet. It should work by changing to 2.7.6. We expect the next release, 4.7.0., that is expected to be released in January to have Spring Boot 3 support.
Law
December 21, 2022, 6:09pm
9
thank you. Now I can continue learning axon.
1 Like