java - 我应该如何初始化类 freemarker.template.Configuration?

标签 java spring tomcat struts2 freemarker

正在尝试关注 this Java tutorial .

在第 63 页中,您被告知如何创建表单(“New.jsp”)以提交新事件。

当我尝试访问该页面时,出现以下错误:

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Filter execution threw an exception
    com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129)
    com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77)
    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
root cause

java.lang.NoClassDefFoundError: Could not initialize class freemarker.template.Configuration
    org.apache.struts2.views.freemarker.FreemarkerManager.createConfiguration(FreemarkerManager.java:294)
    org.apache.struts2.views.freemarker.FreemarkerManager.init(FreemarkerManager.java:255)
    org.apache.struts2.views.freemarker.FreemarkerManager.getConfiguration(FreemarkerManager.java:238)
    org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:734)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:506)
    org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
    com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129)
    com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77)
    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.29 logs.

Apache Tomcat/6.0.29

我在 D:\education\java.metadata.plugins\org.eclipse.wst.server.core\tmp1\logs\localhost_access_log.2010-09-26.txt 找到了这个日志

127.0.0.1 - - [26/Sep/2010:04:29:09 +0200] "GET / HTTP/1.1" 404 953
0:0:0:0:0:0:0:1 - - [26/Sep/2010:04:29:11 +0200] "GET /Events/ HTTP/1.1" 304 -
0:0:0:0:0:0:0:1 - - [26/Sep/2010:04:29:11 +0200] "GET /favicon.ico HTTP/1.1" 404 986
127.0.0.1 - - [26/Sep/2010:04:56:53 +0200] "GET / HTTP/1.1" 404 953
0:0:0:0:0:0:0:1 - - [26/Sep/2010:04:56:55 +0200] "GET /Events/events/Listing.action HTTP/1.1" 200 963
0:0:0:0:0:0:0:1 - - [26/Sep/2010:04:56:55 +0200] "GET /Events/assets/styles.css HTTP/1.1" 304 -
0:0:0:0:0:0:0:1 - - [26/Sep/2010:04:56:55 +0200] "GET /Events/assets/bg.jpg HTTP/1.1" 304 -
0:0:0:0:0:0:0:1 - - [26/Sep/2010:04:56:55 +0200] "GET /Events/assets/alpha-b.png HTTP/1.1" 304 -
0:0:0:0:0:0:0:1 - - [26/Sep/2010:04:56:55 +0200] "GET /Events/assets/alpha-w.png HTTP/1.1" 304 -
0:0:0:0:0:0:0:1 - - [26/Sep/2010:04:56:55 +0200] "GET /favicon.ico HTTP/1.1" 404 986
0:0:0:0:0:0:0:1 - - [26/Sep/2010:05:02:49 +0200] "GET /Events/ HTTP/1.1" 404 974
0:0:0:0:0:0:0:1 - - [26/Sep/2010:05:02:49 +0200] "GET /favicon.ico HTTP/1.1" 404 986

我找不到任何其他日志。

有什么解决办法吗?

最佳答案

NoClassDefFound 表示类定义在编译时存在,但在运行时定义未找到或版本不同

在您的情况下,我认为这可能是在类路径中找到多个版本的 freemarker.template.Configuration 的问题。理想情况下应该只在 freemarker.jar 但 check if you've got one of these jars在您的服务器/库中并删除所有重复项

如果这些都不是,请确保除了你的 war 之外没有其他版本的 freemarker.jar

评论中发现的更新解决方案

将重复的 freemarker.jar 重命名为 .bak 没有帮助,当那些移出路径/类路径时有效

关于java - 我应该如何初始化类 freemarker.template.Configuration?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3799817/

相关文章:

java - 如何永久增加java堆大小

java - 在 servlet 容器启动后立即调用对 localhost 的请求

java - 如何在Mac 10.9.4(其实就是Mac虚拟机)上安装Matlab R2014a?

java - 记录 actionListener 的最佳实践

java - 使用 WebMvcConfigurationSupport 而不是 WebMvcConfigurerAdapter 返回空值

java - 使用@Aspect更改方法签名

apache - 如何将本地主机转移到开放服务器

java - 我如何使用 set 和 get 方法为我的程序询问和检索用户输入?

java - if 语句中的多个 OR 条件

java - Google App Engine 上的 Spring Boot REST 抛出 502