使用Axon Framework编写测试时,可能会遇到聚合根的自动装配bean抛出NullPointerException的问题。该问题的原因是当测试时只使用了axon-test
依赖而忽略了axon-spring-boot-test-autoconfigure
依赖时,会导致自动装配bean无法正常注入。
要解决这个问题,需要添加axon-spring-boot-starter-test
依赖,这个依赖包含了axon-spring-boot-test-autoconfigure
和其他相关的Axon Spring Boot测试支持依赖。
以下是添加axon-spring-boot-starter-test
依赖的示例代码:
org.axonframework
axon-spring-boot-starter-test
${axon.version}
test
添加完依赖之后,自动装配bean就能正常注入到测试中了。