JFinal项目运行报错

来源:本网整理

web.xml照搬手册

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>example</display-name>
  <filter>
        <filter-name>jfinal</filter-name>
        <filter-class>com.jfinal.core.JFinalFilter</filter-class>
        <init-param>
            <param-name>configClass</param-name>
            <param-value>demo.DemoConfig</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>jfinal</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>



DemoConfig代码

public void configConstant(Constants me){
        me.setMainRenderFactory(new BeetlRenderFactory());
        GroupTemplate gt = BeetlRenderFactory.groupTemplate;
    }
    public void configRoute(Routes me) {
        me.add("/", HomeController.class);
        me.add("/login", UserController.class,"/");
    }

    public void configPlugin(Plugins me) {
    	//TODO
    }

    public void configInterceptor(Interceptors me) {
    	//TODO
    }

    public void configHandler(Handlers me) {
    	//TODO
    }
    
    public static void main(String[] args) {
		JFinal.start("WebRoot", 80, "/", 5);
	}



错误信息

Starting JFinal 1.9
Starting scanner at interval of 5 seconds.
Starting web server on port: 80
2015-01-13 22:29:17.501:WARN:oejuc.AbstractLifeCycle:FAILED jfinal: java.lang.RuntimeException: Can not create instance of class: demo.DemoConfig. Please check the config in web.xml
java.lang.RuntimeException: Can not create instance of class: demo.DemoConfig. Please check the config in web.xml
    at com.jfinal.core.JFinalFilter.createJFinalConfig(JFinalFilter.java:104)
    at com.jfinal.core.JFinalFilter.init(JFinalFilter.java:47)
    at org.eclipse.jetty.servlet.FilterHolder.doStart(FilterHolder.java:119)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:724)
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:265)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:706)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:492)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)
    at org.eclipse.jetty.server.Server.doStart(Server.java:277)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    at com.jfinal.server.JettyServer.doStart(JettyServer.java:120)
    at com.jfinal.server.JettyServer.start(JettyServer.java:64)
    at com.jfinal.core.JFinal.start(JFinal.java:159)
    at demo.DemoConfig.main(DemoConfig.java:33)
2015-01-13 22:29:17.503:WARN:oejw.WebAppContext:Failed startup of context o.e.j.w.WebAppContext{/,file:/D:/extend/workspace/example/WebRoot/}
java.lang.RuntimeException: Can not create instance of class: demo.DemoConfig. Please check the config in web.xml
    at com.jfinal.core.JFinalFilter.createJFinalConfig(JFinalFilter.java:104)
    at com.jfinal.core.JFinalFilter.init(JFinalFilter.java:47)
    at org.eclipse.jetty.servlet.FilterHolder.doStart(FilterHolder.java:119)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:724)
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:265)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:706)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:492)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)
    at org.eclipse.jetty.server.Server.doStart(Server.java:277)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    at com.jfinal.server.JettyServer.doStart(JettyServer.java:120)
    at com.jfinal.server.JettyServer.start(JettyServer.java:64)
    at com.jfinal.core.JFinal.start(JFinal.java:159)
    at demo.DemoConfig.main(DemoConfig.java:33)
Starting Complete. Welcome To The JFinal World :)



DemoConfig 有无继承自 JFinalConfig,有无放在 demo 这个包下面?
=======================其他用户的看法====================

引用来自“JFinal”的评论

DemoConfig 有无继承自 JFinalConfig,有无放在 demo 这个包下面?
===========================================

有继承JFinalConfig,class是在WEB-INF下,我想是项目结构不对或运行姿势不对,同样的代码IDEA下跑没问题


===========================================
编译的 class 文件输出路径需要设置为 WEB-INF/classes 才可以
===========================================

引用来自“JFinal”的评论

编译的 class 文件输出路径需要设置为 WEB-INF/classes 才可以
===========================================

引用来自“人人皆为初学者”的评论

有继承JFinalConfig,class是在WEB-INF下,我想是项目结构不对或运行姿势不对,同样的代码IDEA下跑没问题


===========================================

免责声明 - 关于我们 - 联系我们 - 广告联系 - 友情链接 - 帮助中心 - 频道导航
Copyright © 2017 www.zgxue.com All Rights Reserved