Grails 部署问题(WAR 和 Tomcat)

Posted

技术标签:

【中文标题】Grails 部署问题(WAR 和 Tomcat)【英文标题】:Grails deployment issues (WAR & Tomcat) 【发布时间】:2011-05-23 17:00:50 【问题描述】:

我正在努力在远程服务器上的 Tomcat 6 下部署 WAR。现在,如果我在本地机器上部署,一切正常。远程部署会触发一组非常不友好的异常。

log4j:ERROR setFile(null,true) call failed.
java.io.FileNotFoundException: stacktrace.log (Permission denied)
    at java.io.FileOutputStream.openAppend(Native Method)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:207)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:131)
    at org.apache.log4j.FileAppender.setFile(FileAppender.java:294)
    at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:165)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    <...snip>
ERROR  initWebApplicationContext, Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'hibernateProperties' while setting bean property 'hibernateProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (File input/output error prodDB.properties java.io.FileNotFoundException: prodDB.properties.new (Permission denied))
    at java.lang.Thread.run(Thread.java:636)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'hibernateProperties' while setting bean property 'hibernateProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (File input/output error prodDB.properties java.io.FileNotFoundException: prodDB.properties.new (Permission denied))
    ... 1 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'hibernateProperties' while setting bean property 'hibernateProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (File input/output error prodDB.properties java.io.FileNotFoundException: prodDB.properties.new (Permission denied))
    ... 1 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (File input/output error prodDB.properties java.io.FileNotFoundException: prodDB.properties.new (Permission denied))
    ... 1 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (File input/output error prodDB.properties java.io.FileNotFoundException: prodDB.properties.new (Permission denied))
    ... 1 more
Caused by: org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (File input/output error prodDB.properties java.io.FileNotFoundException: prodDB.properties.new (Permission denied))
    ... 1 more
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (File input/output error prodDB.properties java.io.FileNotFoundException: prodDB.properties.new (Permission denied))
    at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1225)
    at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
    at $Proxy15.getMetaData(Unknown Source)
    ... 1 more
Caused by: java.sql.SQLException: File input/output error prodDB.properties java.io.FileNotFoundException: prodDB.properties.new (Permission denied)
    at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
    at org.hsqldb.jdbc.jdbcConnection.<init>(Unknown Source)
    at org.hsqldb.jdbcDriver.getConnection(Unknown Source)
    at org.hsqldb.jdbcDriver.connect(Unknown Source)
    at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
    at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:294)
    at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1247)
    at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1221)
    ... 3 more

我使用 HSQLDB 作为数据库。

Tomcat 作为服务运行,因此不应该有任何权限问题。我是否需要更改某些东西的权限(如果需要,因为我找不到尝试的访问权限)?我可以在 Grails 中设置一个配置选项来不记录或重定向记录吗?

【问题讨论】:

【参考方案1】:

这不是关于日志记录,而是关于“prodDB.properties”。你得到一个 FileNotFoundException 因为它不能写(或可能重命名)它。运行应用程序的用户不得在其创建 HSQLDB 数据库文件的目录中具有写入权限。

默认配置使用相对路径,因此它会写入应用程序从哪里启动:

production 
    dataSource 
        dbCreate = "update"
        url = "jdbc:hsqldb:file:prodDb;shutdown=true"
    

一种解决方法是在 DataSource.groovy 中硬编码路径:

production 
    dataSource 
        dbCreate = "update"
        url = "jdbc:hsqldb:file:/some/writeable/folder/prodDb;shutdown=true"
    

更好的方法是在 Config.groovy 中启用外部配置文件:

grails.config.locations = ["classpath:$appName-config.groovy"]

并创建 foo-config.groovy 包含

dataSource 
    url = "jdbc:hsqldb:file:/some/writeable/folder/prodDb;shutdown=true"

并将 foo-config.groovy 放在 Tomcat 类路径中的 $TOMCAT_HOME/lib 中(将 foo 更改为您的应用程序名称)。这样,您可以将战争部署到多个位置,并且只需覆盖配置文件,而不是在 Config.groovy 中硬编码单个值。

【讨论】:

【参考方案2】:

我在升级到 Windows 7 时突然遇到了这个问题。我一直使用快捷方式启动 Tomcat,我将“Start In”目录设置为纯“C:\”。 Windows 7 不允许非管理员用户写入此目录。我在我的用户主目录中创建了一个名为“TomcatData”的子目录,并更改了我的快捷方式以从那里启动 Tomcat。现在一切正常。

【讨论】:

以上是关于Grails 部署问题(WAR 和 Tomcat)的主要内容,如果未能解决你的问题,请参考以下文章

springSecurityService.principal 在 tomcat 8.5 中部署为 WAR 时返回 Null

在现有站点上使用 Tomcat 部署 Grails 应用程序

如何在 Tomcat7 中部署 Grails 3.0.1 战争文件?

Tomcat“Log4J”上的 Grails WAR 根本不起作用

使用 Tomcat 部署 grails 应用程序的最佳实践

如何在 Tomcat 7 上部署 Grails 3 应用程序?