无法解析依赖Java FX spring boot

时间:2018-04-23 06:59:49

标签: spring-boot javafx dependency-injection javafx-8

我是JavaFX和Spring Boot的新手。我正在尝试使用依赖注入,但依赖性没有得到Autowired。任何人都可以帮忙。

先谢谢。这是我的代码

import de.felixroske.jfxsupport.AbstractJavaFxApplicationSupport;

@SpringBootApplication
@ComponentScan("com.tillster.kisok.installer")
public class Main extends AbstractJavaFxApplicationSupport {


    public static void main(String[] args) {

        System.setProperty("com.sun.javafx.touch", "true");
        System.setProperty("com.sun.javafx.isEmbedded", "true");
        System.setProperty("com.sun.javafx.virtualKeyboard", "none");

        launch(Main.class, KisokInstallDetailView.class, args);
    }

}

这是我的视图文件

import org.springframework.stereotype.Component;
import de.felixroske.jfxsupport.AbstractFxmlView;
import de.felixroske.jfxsupport.FXMLView;

@Component
@FXMLView(value="/view/LanguageMainScreen.fxml", bundle="bundles.locale")
public class KisokInstallDetailView extends AbstractFxmlView {

}

配置文件

     @Configuration
     @ComponentScan("com.kisok.installer")
     public class KISOKConfiguration {
     }
}

控制器

@FXMLController
@Component
public class KisokInstallProgressController implements Initializable {

    @FXML
    VBox hBox;
    @FXML
    WebView webView;

    @Autowired
    @Qualifier("installStepService")
    InstallStepsService installService;

......................

    @Override
    public void initialize(URL location, ResourceBundle resources) {

        Stage stage = Main.getStage();

        WebEngine webEngine = webView.getEngine();

        URL url = this.getClass().getClassLoader().getResource("test.html");
        webEngine.load(url.toString());

        Screen screen = Screen.getPrimary();
        Rectangle2D bounds = screen.getVisualBounds();

        double screenWidth = bounds.getWidth();
        double screenHeight = bounds.getHeight();

        webView.setPrefHeight(screenHeight);
        webView.setPrefWidth(screenWidth);

        hBox.setPrefWidth(screenWidth);
        hBox.setPrefHeight(screenHeight);

        stage.setFullScreen(true);
        stage.setMaximized(true);
        stage.setAlwaysOnTop(true);

        InstallKIOSKDetails installKISOKDtls = installService.getKIOSKDetails();
        System.out.println(installKISOKDtls.getInstallSteps().length);
    }

服务类:

import java.io.File;
import java.io.IOException;

import org.springframework.stereotype.Service;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.tillster.kisok.installer.domain.InstallKIOSKDetails;

@Service("installStepService")
public class InstallStepsServiceImpl implements InstallStepsService {

    private ObjectMapper objectMapper;

    @Override
    public InstallKIOSKDetails getKIOSKDetails() {
        System.out.println("Inside getKIOSKDetails");
        objectMapper = new ObjectMapper();
        InstallKIOSKDetails installKISOKDtls = null;
        File jsonInputFile = new File("E:\\KisokDeployment\\json.txt");
        try {
            installKISOKDtls = objectMapper.readValue(jsonInputFile, InstallKIOSKDetails.class);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return installKISOKDtls;
    }

}

这是例外: javafx.fxml.LoadException: / E:/ MNA%20(3)/installer/target/classes/kioskInstallProgress.fxml

at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
Caused by: java.lang.NullPointerException
    at com.tillster.kisok.installer.controller.KisokInstallProgressController.initialize(KisokInstallProgressController.java:67)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
    ... 64 more

FXML

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Label?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.web.WebView?>


<VBox prefHeight="400.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.tillster.kisok.installer.controller.KisokInstallProgressController">
    <children>
        <MenuBar VBox.vgrow="NEVER" />
        <AnchorPane maxHeight="-1.0" maxWidth="-1.0" prefHeight="-1.0" prefWidth="-1.0" VBox.vgrow="ALWAYS">
            <children>
                <WebView fx:id="webView" layoutX="1.0" />
            </children>
            <children>
                <VBox fx:id="hBox" style="-fx-alignment:center;">
                    <HBox style="-fx-alignment:center;">
                        <VBox fx:id="vBox" layoutX="65.0" layoutY="61.0" prefHeight="819.0" prefWidth="627.0" style="-fx-background-color: #EEE;">
                     <children>
                        <HBox prefHeight="70.0" prefWidth="627.0">
                           <children>
                              <ImageView fx:id="logo" fitHeight="92.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true" />
                              <Label style="-fx-font-size: 20; -fx-padding: 30 5 5 5;" text="Starting Process of Installation" />
                           </children>
                        </HBox>
                        <HBox prefHeight="33.0" prefWidth="627.0" />
                     </children></VBox>

                    </HBox>
                </VBox>
            </children>
        </AnchorPane>
    </children>
</VBox>

0 个答案:

没有答案