问题描述
我正在使用远程服务器上的Tomcat 6部署WAR。现在,如果我在本地机器上部署,一切正常。远程部署触发了一组非常不友好的异常。
log4j:错误setFile(null,true)调用失败。
java.io.FileNotFoundException:stacktrace.log(Permission denied)
at java.io.FileOutputStream.openAppend(Native Method)
at java.io.FileOutputStream。< init>(FileOutputStream .java:207)
在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。
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
< b< ...剪断>
错误initWebApplicationContext,上下文初始化失败
org.springframework.beans.factory.BeanCreationException:创建名为'messageSource'的bean时出错:bean初始化失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名为'transactionManager'的bean时出错:无法在设置bean属性'sessionFactory'时解析对bean'sessionFactory'的引用;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名为'sessionFactory'的bean时出错:在设置bean属性'hibernateProperties'时无法解析对bean'hibernateProperties'的引用;嵌套的异常是org.springframework.beans.factory.BeanCreationException:创建名为'hibernateProperties'的bean时出错:无法使用键[hibernate.dialect]设置Bean属性'属性'来引用bean'dialectDetector';嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名为'dialectDetector'的bean时出错:init方法的调用失败;嵌套的异常是org.springframework.jdbc.support.MetaDataAccessException:提取DatabaseMetaData时出错;嵌套异常是org.apache.commons.dbcp.SQLNestedException:无法创建PoolableConnectionFactory(文件输入/输出错误prodDB.properties java.io.FileNotFoundException:prodDB.properties.new(Permission denied))
at java.lang。 Thread.run(Thread.java:636)
导致:org.springframework.beans.factory.BeanCreationException:创建名为'transactionManager'的bean时出错:无法在设置bean属性'sessionFactory时解析对bean'sessionFactory'的引用;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名为'sessionFactory'的bean时出错:在设置bean属性'hibernateProperties'时无法解析对bean'hibernateProperties'的引用;嵌套的异常是org.springframework.beans.factory.BeanCreationException:创建名为'hibernateProperties'的bean时出错:无法使用键[hibernate.dialect]设置Bean属性'属性'来引用bean'dialectDetector';嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名为'dialectDetector'的bean时出错:init方法的调用失败;嵌套的异常是org.springframework.jdbc.support.MetaDataAccessException:提取DatabaseMetaData时出错;嵌套异常是org.apache.commons.dbcp.SQLNestedException:无法创建PoolableConnectionFactory(文件输入/输出错误prodDB.properties java.io.FileNotFoundException:prodDB.properties.new(Permission denied))
... 1 more
导致:org.springframework.beans.factory.BeanCreationException:创建名为'sessionFactory'的bean时出错:在设置bean属性'hibernateProperties'时无法解析对bean'hibernateProperties'的引用;嵌套的异常是org.springframework.beans.factory.BeanCreationException:创建名为'hibernateProperties'的bean时出错:无法使用键[hibernate.dialect]设置Bean属性'属性'来引用bean'dialectDetector';嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名为'dialectDetector'的bean时出错:init方法的调用失败;嵌套的异常是org.springframework.jdbc.support.MetaDataAccessException:提取DatabaseMetaData时出错;嵌套异常是org.apache.commons.dbcp.SQLNestedException:无法创建PoolableConnectionFactory(文件输入/输出错误prodDB.properties java.io.FileNotFoundException:prodDB.properties.new(Permission denied))
... 1 more
导致:org.springframework.beans.factory.BeanCreationException:创建名为'hibernateProperties'的bean时出错:无法使用键[hibernate.dialect]设置Bean属性'属性'来引用bean'dialectDetector';嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名为'dialectDetector'的bean时出错:init方法的调用失败;嵌套的异常是org.springframework.jdbc.support.MetaDataAccessException:提取DatabaseMetaData时出错;嵌套异常是org.apache.commons.dbcp.SQLNestedException:无法创建PoolableConnectionFactory(文件输入/输出错误prodDB.properties java.io.FileNotFoundException:prodDB.properties.new(Permission denied))
... 1 more
导致:org.springframework.beans.factory.BeanCreationException:创建名为'dialectDetector'的bean时出错:init方法调用失败;嵌套的异常是org.springframework.jdbc.support.MetaDataAccessException:提取DatabaseMetaData时出错;嵌套异常是org.apache.commons.dbcp.SQLNestedException:无法创建PoolableConnectionFactory(文件输入/输出错误prodDB.properties java.io.FileNotFoundException:prodDB.properties.new(Permission denied))
... 1 more
导致:org.springframework.jdbc.support.MetaDataAccessException:提取DatabaseMetaData时出错;嵌套异常是org.apache.commons.dbcp.SQLNestedException:无法创建PoolableConnectionFactory(文件输入/输出错误prodDB.properties java.io.FileNotFoundException:prodDB.properties.new(Permission denied))
... 1 more
导致:org.apache.commons.dbcp.SQLNestedException:无法创建PoolableConnectionFactory(文件输入/输出错误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
导致:java.sql.SQLException:文件输入/输出错误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 Sourc e)
在org.hsqldb.jdbcDriver.getConnection(未知源)
在org.hsqldb.jdbcDriver.connect(未知源)
在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作为数据库。
$ b Tomcat作为服务运行,所以不应该是任何权限问题。我是否需要更改某些内容的权限(如果是这样,因为我找不到尝试访问的内容)?有没有一个配置选项,我可以在Grails中设置为不记录日志或重定向日志记录?
这不是关于日志记录,这是关于prodDB.properties。你会得到一个FileNotFoundException,因为它无法写入(或可能重命名)它。运行应用程序的用户在创建HSQLDB数据库文件的目录中不能具有写许可权。
默认配置使用相对路径,因此它会写入app正在启动:
生产{
dataSource {
dbCreate =update
url =jdbc:hsqldb:file:prodDb; shutdown = true
}
}
一个修正是对DataSource.groovy中的路径进行硬编码:
生产{
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中硬编码一个值。
I'm working on deploying a WAR under Tomcat 6 on a remote server. Now if I deploy as such on my local machine everything works fine. Remote deployment triggers a very unfriendly set of exceptions.
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
I'm using HSQLDB as the database.
Tomcat is run as a service, so there shouldn't be any permission issues. Do I need to change permissions on something (if so where, because I can't find the attempted access)? Is there a configuration option I can set in Grails to either not log or redirect the logging?
This isn't about logging, it's about "prodDB.properties". You're getting a FileNotFoundException because it can't write (or possibly rename) it. The user that's running the app must not have write permission in the directory where it's creating the HSQLDB database files.
The default config uses a relative path, so it's writing wherever the app is launching from:
production {
dataSource {
dbCreate = "update"
url = "jdbc:hsqldb:file:prodDb;shutdown=true"
}
}
One fix is to hard-code the path in DataSource.groovy:
production {
dataSource {
dbCreate = "update"
url = "jdbc:hsqldb:file:/some/writeable/folder/prodDb;shutdown=true"
}
}
A better one is to enable external configuration files in Config.groovy:
grails.config.locations = ["classpath:${appName}-config.groovy"]
and create foo-config.groovy containing
dataSource {
url = "jdbc:hsqldb:file:/some/writeable/folder/prodDb;shutdown=true"
}
and put foo-config.groovy in $TOMCAT_HOME/lib which is in Tomcat's classpath (change foo to your app name). This way you can deploy the war to multiple locations and have just a config file override rather than hard-coding a single value in Config.groovy.
这篇关于Grails部署问题(WAR& Tomcat)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!