2010-12-10 284 views
6

我正在使用遠程服務器上的Tomcat 6部署WAR。現在,如果我在本地機器上部署,一切正常。遠程部署觸發了一組非常不友好的例外情況。Grails部署問題(WAR&Tomcat)

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中設置的配置選項,以便不記錄或重定向日誌記錄?

回答

20

這不是關於日誌記錄,而是關於「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"] 

and crea含$ TOMCAT_HOME/lib目錄是Tomcat的類路徑中(其他城市FOO到您的應用程序名稱)

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

,並把富-TE Con​​fig.groovy文件FOO-Config.groovy中。通過這種方式,您可以將戰爭部署到多個位置,只需要配置文件而不是在Config.groovy中對一個值進行硬編碼。

1

當我升級到Windows 7時,突然遇到了這個問題。我一直使用快捷方式啓動Tomcat,並將「Start In」目錄設置爲「C:\」。 Windows 7不允許非管理員用戶寫入此目錄。我創建了一個名爲「TomcatData」的用戶主目錄的子目錄,並更改了我的快捷方式以從此啓動Tomcat。現在一切正常。