Ich möchte Spring-Boot-Starter-Daten-Jpa Funktionen verwenden, um eine Non-Web-Anwendung zu erstellen. In der 52,4-Dokumentation sagt:So konfigurieren Sie Spring-Boot mit Swing-Anwendung
Anwendungscode, den Sie als Business-Logik ausführen möchten können als CommandLineRunner implementiert werden und fiel in den Kontext als @Bean Definition.
Mein AppPrincipalFrame wie folgt aussieht:
@Component
public class AppPrincipalFrame extends JFrame implements CommandLineRunner{
private JPanel contentPane;
@Override
public void run(String... arg0) throws Exception {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
AppPrincipalFrame frame = new AppPrincipalFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
Und Boot-Anwendungsklasse wie folgt aussieht:
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
ApplicationContext context = SpringApplication.run(Application.class, args);
AppPrincipalFrame appFrame = context.getBean(AppPrincipalFrame.class);
}
}
aber nicht funktioniert. Hat jemand eine Probe dazu?
Bearbeitung und Ausnahme hinzugefügt.
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'appPrincipalFrame'.
Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [es.adama.swing.ui.AppPrincipalFrame]: Constructor threw exception; nested exception is java.awt.HeadlessException
Grüße.
Was "funktioniert" nicht? Gibt es eine Ausnahme? Protokolle? –
@DaveSyer ja, Zusammenfassung Ausnahme hinzugefügt. – Dapaldo
Spring hat Ihren Konstruktor aufgerufen und ist fehlgeschlagen. Es sieht so aus, als ob dieser Konstruktor zweimal aufgerufen wird (einmal bei Spring, um die '@ Component' zu erstellen und einmal bei seiner eigenen' run() 'Methode). Ein bisschen bizarr, also hast du vielleicht nicht einen von denen gemeint? –