55
66import org .apache .catalina .valves .RemoteIpValve ;
77import org .springframework .boot .SpringApplication ;
8- import org .springframework .boot .tomcat .servlet .TomcatServletWebServerFactory ;
9- import org .springframework .boot .web .error .ErrorPage ;
10- import org .springframework .boot .web .server .servlet .ServletWebServerFactory ;
8+ import org .springframework .boot .web .embedded .jetty .JettyServletWebServerFactory ;
9+ import org .springframework .boot .web .embedded .tomcat .TomcatServletWebServerFactory ;
10+ import org .springframework .boot .web .embedded .undertow .UndertowServletWebServerFactory ;
11+ import org .springframework .boot .web .server .ErrorPage ;
1112import org .springframework .boot .web .servlet .ServletContextInitializer ;
13+ import org .springframework .boot .web .servlet .server .AbstractServletWebServerFactory ;
14+ import org .springframework .boot .web .servlet .server .ServletWebServerFactory ;
1215import org .springframework .context .annotation .Bean ;
1316import org .springframework .context .annotation .Configuration ;
1417import org .springframework .context .annotation .Import ;
3437public class SpringBootApplication {
3538
3639 /**
37- * <p>
38- * 在idea中通过main方法启动需要将工作目录改为 publiccms 模块所在的路径,否则静态资源不能加载
39- * <p>
40- * ideaのmainメソッドから始めるには、作業ディレクトリをpubliccmsモジュールが配置されているパスに変更する必要があり、そうしないと静的リソースをロードできません
41- * <p>
42- * To start through the main method in idea, you need to change the working
43- * directory to the path where the publiccms module is located, otherwise
44- * the static resources cannot be loaded
45- * <p>
46- * https://www.publiccms.com/question/2018/02-13/376.html
40+ * <p>在idea中通过main方法启动需要将工作目录改为 publiccms 模块所在的路径,否则静态资源不能加载
41+ * <p>ideaのmainメソッドから始めるには、作業ディレクトリをpubliccmsモジュールが配置されているパスに変更する必要があり、そうしないと静的リソースをロードできません
42+ * <p>To start through the main method in idea, you need to change the working directory to the path where the publiccms module is located, otherwise the static resources cannot be loaded
43+ * <p>https://www.publiccms.com/question/2018/02-13/376.html
4744 *
4845 * @param args
4946 */
@@ -56,10 +53,19 @@ public static void main(String[] args) {
5653 */
5754 @ Bean
5855 public ServletWebServerFactory servletContainer () {
59- TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory ();
60- String initProto = System .getProperty ("cms.initProto" );
61- if (CommonUtils .notEmpty (initProto ) && "false" .equalsIgnoreCase (initProto )) {
62- factory .addEngineValves (new RemoteIpValve ());
56+ String server = System .getProperty ("cms.server" );
57+ AbstractServletWebServerFactory factory = null ;
58+ if ("jetty" .equalsIgnoreCase (server )) {
59+ factory = new JettyServletWebServerFactory ();
60+ } else if ("undertow" .equalsIgnoreCase (server )) {
61+ factory = new UndertowServletWebServerFactory ();
62+ } else {
63+ TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory ();
64+ String initProto = System .getProperty ("cms.initProto" );
65+ if (CommonUtils .notEmpty (initProto ) && "false" .equalsIgnoreCase (initProto )) {
66+ tomcat .addEngineValves (new RemoteIpValve ());
67+ }
68+ factory = tomcat ;
6369 }
6470 Set <ErrorPage > errorPageSet = factory .getErrorPages ();
6571 errorPageSet .add (new ErrorPage (Throwable .class , "/error/500.html" ));
@@ -71,8 +77,8 @@ public ServletWebServerFactory servletContainer() {
7177 factory .setContextPath (System .getProperty ("cms.contextPath" , "" ));
7278 factory .setDisplayName ("PublicCMS" );
7379 factory .setRegisterDefaultServlet (true );
74- factory .getSettings (). getSession ().setTimeout (Duration .ofMinutes (20 ));
75- factory .getSettings (). getJsp ().setRegistered (false );
80+ factory .getSession ().setTimeout (Duration .ofMinutes (20 ));
81+ factory .getJsp ().setRegistered (false );
7682 return factory ;
7783 }
7884
0 commit comments