2015-07-13 139 views
1

我使用SiteMesh的的2.4.2版本春SiteMesh的,不能建工厂:com.opensymphony.module.sitemesh.factory.DefaultFactory:

<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- INF/sitemesh.xml:java.io.FileNotFoundException:

我发现存在于WEB-INF/directory/file中的sitemesh.xml。

你能帮我吗?

回答

1

我们有相同的版本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>