jfinal-undertow应用到ssm框架中

感谢波总的提醒。不用重复造轮子

基于maven项目构建的。

首先引入依赖。

image.png

创建一个继承自 JFinalConfig的类

image.png

由于web.xml中之前有其他全局元素,所以继承了 WebBuilder 做扩展

image.png

继承 UndertowServer

class MyUndertowServer extends UndertowServer {

    Consumer<MyWebBuilder> webBuilderConsumer = e -> {

        e.addInitParam("webAppRootKey", "AppleAPP");

        e.addInitParam("contextConfigLocation", "classpath:spring/ApplicationContext.xml");

        e.addInitParam("log4jConfigLocation", "classpath:log4j.properties");

        e.addListener("org.springframework.web.util.Log4jConfigListener");

        e.addListener("org.springframework.web.context.ContextLoaderListener");

        e.addFilter("encodingFilter", "org.springframework.web.filter.CharacterEncodingFilter")

                .addFilterInitParam("encodingFilter", "encoding", "utf-8")

                .addFilterUrlMapping("encodingFilter", "/*");

        e.addFilter("DruidWebStatFilter", "com.alibaba.druid.support.http.WebStatFilter")

                .addFilterInitParam("DruidWebStatFilter", "exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*")

                .addFilterUrlMapping("DruidWebStatFilter", "/*");

        e.addFilter("LoginFilter", "com.renrencai.util.LoginFilter")

                .addFilterUrlMapping("LoginFilter", "*.do");

        e.addServlet("DruidStatView", "com.alibaba.druid.support.http.StatViewServlet")

                .addServletMapping("DruidStatView", "/druid/*");

        e.addServlet("springMvc", "org.springframework.web.servlet.DispatcherServlet")

                .addServletInitParam("springMvc", "contextConfigLocation", "classpath:spring/ApplicationContext-mvc.xml")

                .setServletLoadOnStartup("springMvc", 1)

                .addServletMapping("springMvc", "/*");

    };

    protected Consumer<MyWebBuilder> builderConsumer = webBuilderConsumer;

    public MyUndertowServer(Class<? extends JFinalConfig> t) {

        super(new UndertowConfig(t));

    }


    public MyUndertowServer(UndertowConfig undertowConfig) {

        super(undertowConfig);

    }

    protected void init() {

        super.builder = Undertow.builder();

        super.configUndertow();

        configWeb();

    }


    protected void configWeb() {

        MyWebBuilder wb = new MyWebBuilder(this);

        builderConsumer.accept(wb);

    }

}

最后启动项目:


public class AdminMain {

    public static void main(String[] args) {


        try {

            MyUndertowServer server = new MyUndertowServer(MyJFinalConfig.class);


            server.config(config -> config.setSessionTimeout(30));


            server.start();

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

}

可自行添加 undertow.txt undertow-pro.txt  作配置

undertow.devMode=true
undertow.port=8090
undertow.host=0.0.0.0
undertow.contextPath=/
undertow.gzip.enable=true
undertow.gzip.level=5
undertow.gzip.minLength=1024
undertow.ioThreads=4


评论区

zhangshiqiang

2018-12-17 17:45

idea maven 出现问题,所以有重复依赖自行删除即可 spring 4.3.17

zhangshiqiang

2018-12-17 17:46

其他打包的 package.xml、start.sh、stop.sh 还有 打包插件别忘了

JFinal

2018-12-17 17:47

这个操作相当溜,赞

山东小木

2018-12-17 18:21

学而不思则罔

2019-02-18 16:35

请教作者有没有遇到过这个问题?@zhangshiqiang https://www.jfinal.com/feedback/5291#replyContent

zhangshiqiang

2019-02-18 20:35

@学而不思则罔 我是jar包,没试过 war包

热门分享

扫码入社