配置彈簧引導我想用彈簧引導起動數據JPA功能來創建一個非web aplication。 在52.4文件說:您要爲您的業務邏輯運行如何使用Swing應用程序
應用程序代碼可以 實現爲CommandLineRunner投進的背景下作爲 @Bean定義。
我AppPrincipalFrame樣子:
@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();
}
}
});
}
而且啓動應用程序類樣子:
@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);
}
}
但不起作用。有人有關於此的樣本?
編輯和異常增加。
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
問候。
它是什麼,「不工作」?是否有例外?日誌? –
@DaveSyer是的,添加了摘要異常。 – Dapaldo
Spring調用你的構造函數,如果失敗。看起來構造函數將被調用兩次(一次由Spring創建你的'@ Component',一次在它自己的'run()'方法中)。有點怪異,也許你不打算其中之一? –