我们正在尝试将我们的应用程序从Spring迁移到Quarkus Spring。我们可以根据需要重写我们的应用程序逻辑。问题来了,因为我们正在使用共享的弹簧罐,这是遗留下来的,而且数量很多。大多数spring jar都使用@Autowired来使用依赖注入,但是被注入的对应类没有@Component注解。
将用例子描述问题:
类"MyProject"属于Quarkus应用程序
public class MyProject {
@Autowired
private OtherLevelOne otherLevelOne;
public void invokeMe() {
this.otherLevelOne.call();
}
}
类OtherLevelOne和OtherLevelTwo属于依赖spring jar。
public class OtherLevelOne {
@Autowired
private OtherLevelTwo otherLevelTwo;
public void call() {
this.otherLevelTwo.otherCall();
}
}
public class OtherLevelTwo {
public void otherCall() {
}
}
面临问题。
During compilation of Quakrus Application we get error:
[ERROR] Failed to execute goal io.quarkus.platform:quarkus-maven-plugin:2.1.3.Final:build (quarkus-app-build) on project service-quarkus: Failed to build quarkus application: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[ERROR] [error]: Build step io.quarkus.arc.deployment.ArcProcessor#validate threw an exception: javax.enterprise.inject.spi.DeploymentException: Found 2 deployment problems:
[ERROR] [1] Unsatisfied dependency for type OtherLevelOne and qualifiers [@Default]
Things Tried:为OtherLevelOne和OtherLevelTwo添加了一个Producer类。这有助于解决编译时不满意的依赖问题,并成功构建。但是现在我们在运行时遇到了一个NullPointException,当方法callcall;of OtherLevelOne试图访问"otherleveltwo"的实例。看来二级注射没有发生。可能Quarkus不支持这个(如果不做一些修改,比如在依赖jar中的所有类中添加beans.xml和@Component注释)。
@Dependent
public class ProducerClass {
@Produces
public OtherLevelOne createOtherLevelOne() {
return new OtherLevelOne();
}
@Produces
public OtherLevelTwo createOtherLevelTwo(){
return new OtherLevelTwo();
}
}
问题- 有没有一种方法可以让夸克在这种情况下工作,而不需要编译夸克的所有依赖关系? 是否有可能编写一个Quarkus扩展,可以帮助实现所需类型的依赖注入?
谢谢。
在quarkus中不支持通过XML配置,因此您需要创建一个生产者方法来制作OtherLevelOne
和OtherLevelTwo
bean