NutzCN Logo
问答 nutzwk整合undertow,找不到WEB-INF
发布于 2644天前 作者 wx_8av4gnsr0tjunfiq87qk 1806 次浏览 复制 上一个帖子 下一个帖子
标签: nutzwk

1:web.properties里:

# 绑定请求的IP,默认 0.0.0.0
web.ip=0.0.0.0
# 应用监听的端口,默认 8080
web.port=8080
# 应用ContextPath,默认 /
web.path=/
# 应用的资源文件路径,默认 src/main/webapp/
web.root=src/main/webapp/

# session缓存时长,默认 20
web.session=20
# 应用的运行模式,默认 dev ,暂时没有实际使用
web.runmode=dev
# web.thread.io 指定 io 线程数,用于性能调优,可选
# web.thread.worker 指定应用工作线程数,用于性能调优,可选

2:启动类:

public class MainLauncher {

    private static Log log = Logs.get();

    public MainLauncher() {
    }

    public static void main(String[] args) throws Exception {
        start(args);
    }

    public static void start(String[] args) {
        start(args, getDefaultBuilder(), getDefaultServletBuilder());
    }

    public static void start(String[] args, Undertow.Builder builder) {
        start(args, builder, getDefaultServletBuilder());
    }

    public static void start(String[] args, Undertow.Builder builder, DeploymentInfo servletBuilder) {
        WebConfig conf = WebConfig.NewByArgs(args);
        start(conf, builder, servletBuilder);
    }

    public static void start(WebConfig conf) {
        start(conf, getDefaultBuilder(), getDefaultServletBuilder());
    }

    public static void start(WebConfig conf, Undertow.Builder builder) {
        start(conf, builder, getDefaultServletBuilder());
    }

    public static void start(WebConfig conf, Undertow.Builder builder, DeploymentInfo servletBuilder) {
        String contextPath = conf.getContextPath();
        servletBuilder.setContextPath(contextPath).setDefaultSessionTimeout(conf.getSession()).setDeploymentName("nutz-web");
        addDefaultFilter(servletBuilder, conf);

        servletBuilder.addWelcomePages("index.html", "index.htm", "index.do");

        DeploymentManager manager = Servlets.defaultContainer().addDeployment(servletBuilder);
        manager.deploy();

        HttpHandler servletHandler;
        try {
            servletHandler = manager.start();

        } catch (Exception var8) {
            throw Lang.wrapThrow(var8);
        }

        PathHandler pathHandler;
        if("/".equals(contextPath)) {
            pathHandler = Handlers.path(servletHandler);
        } else {
            pathHandler = Handlers.path(Handlers.redirect(contextPath)).addPrefixPath(contextPath, servletHandler);
        }

        builder.addHttpListener(conf.getPort(), conf.getIp()).setHandler(pathHandler);
        final Undertow server = builder.build();
        server.start();
        log.infof("*** WebServer start at %s:%d! ***", conf.getIp(), conf.getPort());
        Runtime.getRuntime().addShutdownHook(new Thread() {
            public void run() {
                server.stop();
            }
        });
    }

    public static Undertow.Builder getDefaultBuilder() {
        return Undertow.builder();
    }

    public static DeploymentInfo getDefaultServletBuilder() {
        return Servlets.deployment().setClassLoader(DeploymentInfo.class.getClassLoader()).setEagerFilterInit(true);
    }

    protected static void addDefaultFilter(DeploymentInfo servletBuilder, WebConfig conf) {

        ListenerInfo shiroListener = new ListenerInfo(EnvironmentLoaderListener.class);
        servletBuilder.addListener(shiroListener);

        FilterInfo shiroFilter = new FilterInfo("ShiroFilter", ShiroFilter.class);
        servletBuilder.addFilter(shiroFilter).addFilterUrlMapping("ShiroFilter", "/*", DispatcherType.REQUEST)
                .addFilterUrlMapping("ShiroFilter", "/*", DispatcherType.FORWARD).addFilterUrlMapping("ShiroFilter", "/*", DispatcherType.INCLUDE)
                .addFilterUrlMapping("ShiroFilter", "/*", DispatcherType.ERROR);


        FilterInfo nutzFilter = new FilterInfo("mvc", NutFilter.class);
        nutzFilter.addInitParam("modules", "cn.wizzer.app.web.commons.core.Module");
        nutzFilter.addInitParam("ignore", "^(.+[.])(jsp|png|gif|jpg|js|css|jspx|jpeg|html|mp3|mp4|ico)$");
        nutzFilter.addInitParam("exclusions", "/assets/*,/druid/*,/upload/*,/apidoc/*");
        servletBuilder.addFilter(nutzFilter).addFilterUrlMapping("mvc", "/*", DispatcherType.REQUEST)
                .addFilterUrlMapping("mvc", "/*", DispatcherType.FORWARD).addFilterUrlMapping("mvc", "/*", DispatcherType.INCLUDE)
                .addFilterUrlMapping("mvc", "/*", DispatcherType.ERROR);


        FilterInfo routeFilter = new FilterInfo("route", RouteFilter.class);
        servletBuilder.addFilter(routeFilter).addFilterUrlMapping("route","/*",DispatcherType.FORWARD)
                .addFilterUrlMapping("route","/*",DispatcherType.ASYNC)
                .addFilterUrlMapping("route","/*",DispatcherType.REQUEST)
                .addFilterUrlMapping("route","/*",DispatcherType.INCLUDE)
                .addFilterUrlMapping("route","/*",DispatcherType.ERROR);



        File resRootDir = Files.findFile(conf.getRoot());
        if(resRootDir != null && resRootDir.isDirectory()) {
            servletBuilder.setResourceManager(new FileResourceManager(resRootDir, 100L));
        } else {
            servletBuilder.setResourceManager(new ClassPathResourceManager(DeploymentInfo.class.getClassLoader(), "webapp/"));
        }

    }
}

3:报错信息:

[DEBUG] 2017-08-04 11:01:48,334 cn.wizzer.app.web.commons.processor.LogTimeProcessor.process(LogTimeProcessor.java:26) - [GET ]URI=/platform/login 490ms
[WARN ] 2017-08-04 11:01:48,335 org.nutz.mvc.impl.processor.FailProcessor.process(FailProcessor.java:28) - Error@/platform/login :
java.lang.NullPointerException
	at org.beetl.core.GroupTemplate.loadTemplate(GroupTemplate.java:612)
	at org.beetl.core.GroupTemplate.getTemplateByLoader(GroupTemplate.java:562)
	at org.beetl.core.GroupTemplate.getTemplate(GroupTemplate.java:526)
	at org.beetl.ext.web.WebRender.render(WebRender.java:85)
	at org.beetl.ext.nutz.BeetlView.render(BeetlView.java:28)
	at org.nutz.mvc.view.ViewZone.render(ViewZone.java:53)
	at org.nutz.mvc.impl.processor.ViewProcessor.process(ViewProcessor.java:60)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:33)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.wizzer.app.web.commons.processor.XssSqlFilterProcessor.process(XssSqlFilterProcessor.java:35)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.wizzer.app.web.commons.processor.NutShiroProcessor.process(NutShiroProcessor.java:52)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.wizzer.app.web.commons.processor.GlobalsSettingProcessor.process(GlobalsSettingProcessor.java:36)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.wizzer.app.web.commons.processor.LogTimeProcessor.process(LogTimeProcessor.java:21)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
	at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
	at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
	at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
	at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
	at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
	at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
	at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
	at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
	at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
	at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
	at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
	at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
	at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
	at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
	at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
	at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
	at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
	at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
	at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
	at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
	at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
	at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
	at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
	at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
	at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
	at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
	at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
	at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
	at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
	at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
	at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
	at io.undertow.server.Connectors.executeRootHandler(Connectors.java:326)
	at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:812)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
3 回复

undertow不读web.xml,里面的配置都需要转为代码来实现

多谢,已经解决。
pom.xml里添加

 <resource>
                <directory>src/main/webapp</directory>
                <targetPath>${project.build.directory}/classes/webapp</targetPath>
                <includes>
                    <include>**/*</include>
                </includes>
            </resource>

这样基于undertow启动的时候,webapp下的资源不能自动更新了。

添加回复
请先登陆
回到顶部