我在Spring中使用了2.4.2版的SiteMesh
<dependency>
<groupId>opensymphony</groupId>
<artifactId>sitemesh</artifactId>
<version>2.4.2</version>
</dependency>我使用名称myApp.war部署我的应用程序,一切都正常工作。我需要部署应用程序myapp##versionApp.war名称,这个名称会出现问题。
错误是
无法构造工厂: com.opensymphony.module.sitemesh.factory.DefaultFactory: com.opensymphony.module.sitemesh.factory.FactoryException:无法读取配置文件:/WEB/sitemesh.xml: java.io.FileNotFoundException:
我发现WEB/目录/文件中存在sitemesh.xml。
你能帮帮我吗?
发布于 2016-07-01 13:34:01
我们在2.4版中也有相同的版本
DefaultFactory将尝试使用ServletContext().getRealPath(),但最终尝试从contexPath读取。我觉得这是个错误。
要解决这个问题,您必须创建自己的工厂,并在web.xml env中设置它
复制代码的DefaultFactory
public class MyFactory extends com.opensymphony.module.sitemesh.factory.BaseFactory {
public MyFactory () {
// Do stuff
// delete every thing that sets the config path or simply set
String configFile = null;
// Do stuff
}
// Do other stuff
}您的web.xml将如下所示
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<env-entry>
<env-entry-name>sitemesh.factory</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>my.sitemesh.MyFactory</env-entry-value>
</env-entry>发布于 2020-04-06 12:44:04
在为遗留应用程序将Tomcat版本从7升级到9时,我在2.3版中也遇到了同样的问题。
问题是DefaultFactory类上的这两行。
this.configFileName = config.getServletContext().getInitParameter("sitemesh.configfile");
.
.
.
.
is = this.configFile.toURL().openStream();通过将configFileName在web.xml文件上定义为上下文-param,可以解决文件名问题.
<context-param>
<param-name>sitemesh.configfile</param-name>
<param-value>/WEB-INF/sitemesh.xml</param-value>
</context-param>配置文件流上不推荐的方法使用会导致问题。要解决这个问题,应该编写自定义工厂类。您可以直接复制defaultFactory并替换这一行
is = this.configFile.toURL().openStream();有了这个
is = new FileInputStream(this.configFile);此更改将解决输入流问题。
我添加的环境条目您可以将您的自定义类添加到sitemesh。这一行应该放在web.xml文件中。
<env-entry>
<env-entry-name>sitemesh.factory</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>your.custom.factory.SitemeshFactory</env-entry-value>
</env-entry>发布于 2020-05-29 01:55:31
DefaultFactory.java使用不推荐的File.toURL() API。读取sitemesh.xml文件时出现问题。
请将您的站点版本更新为sitemesh:2.5-亚特兰-11
https://stackoverflow.com/questions/31379089
复制相似问题