0
我正在使用Embedded Jetty和Spring MVC,并且通过主函数启动我的WebApplication。 我不喜欢它看起来的样子,它不是很干净,我觉得我做错了什么,即使它工作得很好。 我的问题是,我想初始化主方法之外的ServerHolder,ServletContextHandler和Server对象,但是我不能这样做,因为DispatcherServlet需要和ApplicationContext。嵌入式Jetty + Spring MVC主要方法
任何想法?
public static void main(String[] args) throws Exception {
AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
applicationContext.register(EPConfiguration.class);
ServletHolder servletHolder = new ServletHolder(new DispatcherServlet(applicationContext));
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
context.addServlet(servletHolder, "/*");
BasicConfigurator.configure();
Server server = new Server();
server.setHandler(context);
//HTTP
ServerConnector connector = new ServerConnector(server);
connector.setPort(9999);
server.setConnectors(new Connector[]{connector});
server.start();
server.join();
}