के साथ वसंत-बूट को कॉन्फ़िगर कैसे करें मैं गैर-वेब अनुप्रयोग बनाने के लिए वसंत-बूट-स्टार्टर-डेटा-जेपीए सुविधाओं का उपयोग करना चाहता हूं। 52.4 प्रलेखन में कहते हैं:स्विंग एप्लिकेशन
आवेदन कोड है कि आप अपने व्यापार तर्क के रूप में चलाना चाहते हैं एक 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
सम्मान।
यह क्या है कि "काम नहीं करता"? क्या कोई अपवाद है? लॉग्स? –
@ डेवसियर हां, संक्षेप में अपवाद जोड़ा गया। – Dapaldo
वसंत ने आपके कन्स्ट्रक्टर को बुलाया और यदि विफल हुआ। ऐसा लगता है कि कन्स्ट्रक्टर को दो बार बुलाया जा रहा है (एक बार स्प्रिंग द्वारा आपके '@ घटक' बनाने के लिए और एक बार अपनी 'रन()' विधि में)। थोड़ा विचित्र, तो शायद आप उनमें से एक का इरादा नहीं था? –