第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Spring Boot + JavaFx 自動裝配不起作用

Spring Boot + JavaFx 自動裝配不起作用

九州編程 2023-08-09 16:24:02
昨天我嘗試創(chuàng)建連接 Spring Boot 和 JavaFX 的項(xiàng)目。因此,我創(chuàng)建了一個項(xiàng)目,當(dāng)我運(yùn)行應(yīng)用程序時(shí),將創(chuàng)建 spring 上下文并運(yùn)行 JavaFx 應(yīng)用程序。但問題是當(dāng)我嘗試創(chuàng)建一些bean時(shí),例如使用@Repository注釋。當(dāng)我自動裝配時(shí),值為空。CarGarageApplication.javapackage com.car.garage;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.context.ConfigurableApplicationContext;import org.springframework.context.annotation.ComponentScan;import org.springframework.data.jpa.repository.config.EnableJpaRepositories;import com.car.garage.dao.UsersRepository;import javafx.application.Application;import javafx.fxml.FXMLLoader;import javafx.scene.Parent;import javafx.scene.Scene;import javafx.stage.Stage;@SpringBootApplication@ComponentScan@EnableJpaRepositories("com.car.garage.dao")public class CarGarageApplication extends Application {? ? private ConfigurableApplicationContext mainContext;? ? private Parent rootNode;? ? @Autowired? ? UsersRepository usersRepository;? ? public static void main(String[] args) {? ? ? ? Application.launch(args);? ? }? ? @Override? ? public void init() throws Exception {? ? ? ? mainContext = SpringApplication.run(CarGarageApplication.class);? ? ? ? FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/WelcomePage.fxml"));? ? ? ? loader.setControllerFactory(mainContext::getBean);? ? ? ? rootNode = loader.load();? ? }? ? @Override? ? public void start(Stage primaryStage) throws Exception {? ? ? ? primaryStage.setScene(new Scene(rootNode));? ? ? ? primaryStage.setResizable(false);? ? ? ? primaryStage.show();? ? ? ? System.out.println(usersRepository);? ? }? ? @Override? ? public void stop() throws Exception {? ? ? ? mainContext.close();? ? }}
查看完整描述

1 回答

?
慕村9548890

TA貢獻(xiàn)1884條經(jīng)驗(yàn) 獲得超4個贊

我們應(yīng)該遵循以下方法來自動裝配存儲庫類。因?yàn)閺淖詣友b配另一個類的地方必須有 SPRING STEREOTYPES 類(@Component,@Service 這樣的)


@Component

 public class Anotherclass{


     @Autowired

     private UsersRepository usersRepository;

}


查看完整回答
反對 回復(fù) 2023-08-09
  • 1 回答
  • 0 關(guān)注
  • 207 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號