我想使用spring-boot-starter-data-jpa功能来创建非Web应用程序.在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();
}
}
});
}
Run Code Online (Sandbox Code Playgroud)
和启动应用程序类的样子:
@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);
}
}
Run Code Online (Sandbox Code Playgroud)
但是不起作用.有人有这方面的样品吗?
编辑和例外添加.
Exception in …Run Code Online (Sandbox Code Playgroud)