Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/375.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Sitemesh,无法构造工厂:com.opensymphony.module.Sitemesh.Factory.DefaultFactory:_Java_Html_Spring_Jsp_Sitemesh - Fatal编程技术网

Java Sitemesh,无法构造工厂:com.opensymphony.module.Sitemesh.Factory.DefaultFactory:

Java Sitemesh,无法构造工厂:com.opensymphony.module.Sitemesh.Factory.DefaultFactory:,java,html,spring,jsp,sitemesh,Java,Html,Spring,Jsp,Sitemesh,我使用带有Spring的SiteMesh版本2.4.2 <dependency> <groupId>opensymphony</groupId> <artifactId>sitemesh</artifactId> <version>2.4.2</version> </dependency> 开放交响乐团 网站 2.4.2 我使用名称myAp

我使用带有Spring的SiteMesh版本2.4.2

<dependency>
        <groupId>opensymphony</groupId>
        <artifactId>sitemesh</artifactId>
        <version>2.4.2</version>
    </dependency>

开放交响乐团
网站
2.4.2
我使用名称myApp.war部署我的应用程序,一切正常。我需要部署应用程序myapp##versionApp.warname,这个名称会带来问题

错误是

无法构造工厂:com.opensymphony.module.sitemesh.Factory.DefaultFactory:com.opensymphony.module.sitemesh.Factory.Factory异常:无法读取配置文件:/WEB-INF/sitemesh.xml:java.io.FileNotFoundException:

我发现它存在于WEB-INF/目录/文件sitemesh.xml中


你能帮我吗?

我们在2.4版中也有同样的版本

DefaultFactory将尝试使用ServletContext().getRealPath(),但最终尝试从contexPath读取。我认为这是一个错误

要解决这个问题,您必须创建自己的工厂,并将其设置在web.xml环境中

复制代码的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>

斯泰梅斯工厂
java.lang.String
my.sitemesh.MyFactory

在将Tomcat版本从7升级到9时,我在版本2.3中遇到了同样的问题

问题是DefaultFactory类上的这两行

 this.configFileName = config.getServletContext().getInitParameter("sitemesh.configfile");
 .
 .
 .
 .

 is = this.configFile.toURL().openStream();
通过将web.xml文件上的configFileName定义为上下文参数,可以解决文件名问题

<context-param>
    <param-name>sitemesh.configfile</param-name>
    <param-value>/WEB-INF/sitemesh.xml</param-value>
</context-param>
用这个

 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>

斯泰梅斯工厂
java.lang.String
您的.custom.factory.SitemeshFactory

DefaultFactory.java使用不推荐的文件.toURL()API。读取sitemesh.xml文件时出现问题

请将您的sitemesh版本更新为

<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>