@Autowired注释给出了NullPointerException

时间:2017-01-22 14:47:30

标签: java spring javafx

这是我在garmentFactory

上返回NullPointerException的代码段

GarmentFactoryApplicationLauncher加载/config/applicationContext.xml

public class GarmentFactoryApplicationLauncher extends Application{

@Override
public void start(Stage stage) throws Exception {
    Parent root = FXMLLoader.load(getClass().getResource("/fxml/clientInterface.fxml"));
    stage.setScene(new Scene(root));
    stage.setResizable(false);
    stage.initStyle(StageStyle.UTILITY);
    stage.setTitle("GarmentFactory Factory");
    stage.show();
}

public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("/config/applicationContext.xml");
    launch(args);
  }
}

这是applicationContext.xml文件夹

下的resources/config文件
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-2.5.xsd">

    <context:annotation-config />
    <context:component-scan base-package="com.design"/>

</beans>
此文件中出现

错误,在NullPointerException

上显示garmentFactory
@Component
public class ClientInterfaceController implements Initializable {

    @FXML
    private ChoiceBox garmentSelectionChoiceBox;

    @FXML
    private TextField displaySelectionTextField;

    @Autowired
    private GarmentFactory garmentFactory;

    public void initialize(URL location, ResourceBundle resources) {

    }

    /**
     * call the garment factory to produce garment of specific type
     */
    @FXML
    public void OnClickGetBtn(){
        String garmentCode  = (String)garmentSelectionChoiceBox.getSelectionModel().getSelectedItem();
        Garment garment = garmentFactory.getGarment(garmentCode);
        displaySelectionTextField.setText(garment.toString());

    }
}

GarmentFactory注释为@Component,是具有一些逻辑的基本java类

我错过了什么/做错了什么

由于

0 个答案:

没有答案