java - 没有合格的 bean - FxWeaver 和 Spring Boot
问题描述
我正在尝试重构我去年编写的 Java 程序以使用 Spring Boot。前端使用 JavaFX,所以我尝试使用 FxWeaver。
但是,当我运行程序时,启动时出现以下错误:
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:835)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'net.rgielen.fxweaver.core.FxWeaver' available
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:351)
...
在rgielen 的网站上,没有必要提供 RxWeaver “......使用 Spring Boot Starter 时,因为它为 FxWeaver 实例提供了自动配置。”
所以我很困惑为什么我会收到这个错误。请问有人可以看看吗?
主要应用
package application;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import javafx.application.Application;
@SpringBootApplication
public class MainApplication {
public static void main(String[] args) {
Application.launch(SpringbootJavaFxApplication.class, args);
}
}
SpringBootJavaFxApplication
package application;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import net.rgielen.fxweaver.core.FxWeaver;
public class SpringbootJavaFxApplication extends Application {
private ConfigurableApplicationContext applicationContext;
@Override
public void init() throws Exception {
this.applicationContext = new SpringApplicationBuilder()
.sources(MainApplication.class)
.run(getParameters().getRaw().toArray(new String[0]));
}
@Override
public void start(Stage stage) {
FxWeaver fxWeaver = applicationContext.getBean(FxWeaver.class);
Parent root = fxWeaver.loadView(Controller.class);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
@Override
public void stop() {
this.applicationContext.close();
Platform.exit();
}
}
绒球
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>xxxxx</groupId>
<artifactId>xxxxx</artifactId>
<version>1.0</version>
<name>xxxxx</name>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>12.0.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.rgielen</groupId>
<artifactId>javafx-weaver-spring-boot-starter</artifactId>
<version>1.3.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.3</version>
<configuration>
<mainClass>application.Main</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
(显然 pom 包含与此问题无关的内容,但我将整个文件包括在内,以防其他任何东西导致此问题。)
如果您解决了导致问题的原因,请告诉我?我现在用这个把头发扯掉了!
另外,如果我没有提供正确/足够的信息,我们深表歉意。这是我在这里的第一篇文章。我正在使用日食。
谢谢!
解决方案
也许我来不及提供帮助,但是:
我基于最小的 pom 和您的 Java 代码重新创建了一个示例。不过,我无法重现您的问题。
这是我的pom:
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>net.rgielen.sample</groupId>
<artifactId>fxweaver-springboot-starter-sample</artifactId>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.rgielen</groupId>
<artifactId>javafx-weaver-spring-boot-starter</artifactId>
<version>1.3.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
我和你的 pom 有什么关系
java.version
它添加了对 OpenJFX 12(针对 JDK 12)的依赖,但使用目标 1.8 进行编译——在 Spring Boot 应用程序中使用该属性更容易定义。当使用带有嵌入式 JavaFX(Oracle、Liberica)的 1.8 JRE 时,您根本不需要 OpenJFX 部门javafx-maven-plugin
打包为 Spring Boot 应用程序时不需要。
也就是说,我不认为这是根本原因。
如果要详细比较,代码如下: https ://github.com/rgielen/fxweaver-springboot-stripped-demo
推荐阅读
- c++ - C++17。处理使用 auto 相关的模板参数。代码排序的困难
- unit-testing - 测试用例中的lateinit问题
- selenium - Finding Xpath of element within angular table
- javascript - 如何使用 shopify Polaris DropZone 组件上传图片
- reactjs - 反应 + gsap + scrollMagic
- arrays - Empty output when populating 2D range with array
- c++ - 使用 FASTBuild 分布式构建时找不到 mspdbcore.dll
- powershell - Powershell,Get-MailboxPermission 返回权限,但不能用 Remove-MailboxPermission 更改
- android - 如何在 React Native 项目版本 0.61.x 中重新生成 Android 和 IOS 文件夹?
- ios - 如何使应用程序允许与 SwiftNIO 的传入网络连接?