这是我在garmentFactory
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类
我错过了什么/做错了什么
由于