From 9a944e03a5ca4737b6ead3c6539fe94e152589da Mon Sep 17 00:00:00 2001 From: kerry Date: Fri, 20 Jul 2018 16:30:12 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-9843=20=E3=80=9010.0=E4=BA=8C=E8=BD=AE?= =?UTF-8?q?=E5=9B=9E=E5=BD=92=E3=80=91ie9=E5=8F=8A=E4=BB=A5=E4=B8=8A?= =?UTF-8?q?=E7=89=88=E6=9C=AC=EF=BC=8C=E9=A2=84=E8=A7=88=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?css=E6=A0=B7=E5=BC=8F=E7=9A=84=E6=A8=A1=E6=9D=BF=EF=BC=8C?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E4=B8=8D=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/FineEmbedServerActivator.java | 61 +++++++------------ 1 file changed, 23 insertions(+), 38 deletions(-) diff --git a/designer-base/src/main/java/com/fr/start/server/FineEmbedServerActivator.java b/designer-base/src/main/java/com/fr/start/server/FineEmbedServerActivator.java index 2292da99a3..176db579af 100644 --- a/designer-base/src/main/java/com/fr/start/server/FineEmbedServerActivator.java +++ b/designer-base/src/main/java/com/fr/start/server/FineEmbedServerActivator.java @@ -12,8 +12,6 @@ import com.fr.third.springframework.web.context.support.AnnotationConfigWebAppli import com.fr.workspace.WorkContext; import org.apache.catalina.Context; import org.apache.catalina.LifecycleException; -import org.apache.catalina.Wrapper; - import org.apache.catalina.loader.WebappLoader; import org.apache.catalina.startup.Tomcat; @@ -25,12 +23,12 @@ import java.util.Set; * Created by juhaoyu on 2018/6/5. */ public class FineEmbedServerActivator extends Activator { - + private Tomcat tomcat; - + @Override public synchronized void start() { - + try { //初始化tomcat initTomcat(); @@ -39,10 +37,10 @@ public class FineEmbedServerActivator extends Activator { FineLoggerFactory.getLogger().error(e.getMessage(), e); } } - + @Override public synchronized void stop() { - + try { stopSpring(); stopServerActivator(); @@ -51,75 +49,62 @@ public class FineEmbedServerActivator extends Activator { FineLoggerFactory.getLogger().error(e.getMessage(), e); } } - + private void initTomcat() { - + tomcat = new Tomcat(); - + tomcat.setPort(DesignerEnvManager.getEnvManager().getEmbedServerPort()); // 设置解码uri使用的字符编码 tomcat.getConnector().setURIEncoding(EncodeConstants.ENCODING_UTF_8); String docBase = new File(WorkContext.getCurrent().getPath()).getParent(); String appName = "/" + FRContext.getCommonOperator().getAppName(); Context context = tomcat.addContext(appName, docBase); - addDefaultServlet(context); + Tomcat.initWebappDefaults(context); //覆盖tomcat的WebAppClassLoader context.setLoader(new FRTomcatLoader()); - + //直接指定initializer,tomcat就不用再扫描一遍了 SpringServletContainerInitializer initializer = new SpringServletContainerInitializer(); Set> classes = new HashSet>(); classes.add(FineWebApplicationInitializer.class); context.addServletContainerInitializer(initializer, classes); } - - private void addDefaultServlet(Context context) { - - Wrapper defaultServlet = context.createWrapper(); - defaultServlet.setName("default"); - defaultServlet.setServletClass("org.apache.catalina.servlets.DefaultServlet"); - defaultServlet.addInitParameter("debug", "0"); - defaultServlet.addInitParameter("listings", "false"); - defaultServlet.setLoadOnStartup(1); - defaultServlet.setOverridable(true); - context.addChild(defaultServlet); - context.addServletMapping("/","default"); - } - - + + private void stopServerActivator() { - + ModuleRole.ServerRoot.stop(); } - + private void stopSpring() { - + AnnotationConfigWebApplicationContext context = ModuleRole.ServerRoot.getSingleton(AnnotationConfigWebApplicationContext.class); if (context != null) { context.stop(); context.destroy(); } } - + private void stopTomcat() throws LifecycleException { - + tomcat.stop(); tomcat.destroy(); } - - + + /** * Created by juhaoyu on 2018/6/5. * 自定义的tomcat loader,主要用于防止内置服务器再加载一遍class */ private static class FRTomcatLoader extends WebappLoader { - + @Override public ClassLoader getClassLoader() { - + return this.getClass().getClassLoader(); } - + } - + }