grails war java.sql.SQLException:Io 异常:端口号的数字格式无效
奇怪的问题 - 我们在 Windows 上构建了一个 grails 项目,它工作正常,但在 unix 机器上得到:
java.sql.SQLException: Io exception: Invalid number format for port number
(stack trace below)
很奇怪,因为我们定义数据源来自 jndi:
DataSource.groovy: <代码>
envName {
dataSource {
dbCreate = "none"
jndiName = "java:comp/env/jdbc/ourDataSource"
dialect="org.hibernate.dialect.Oracle10gDialect"
}
jndi 由应用程序服务器上 context.xml 中的设置处理: <代码>
<Resource name="jdbc/ourDataSource"
auth="Container"
type="javax.sql.DataSource"
username="OUR_DB_USERNAME"
password="OUR_DB_PASSWORD"
driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@host:1521:sid"
maxActive="8"
maxIdle="4"/>
我们希望构建与环境无关。检查增量:
两者都使用略有不同的 JDK 版本 - unix 上为 1.6.0_21,windows 上为 1.6.0_22。假设这不会成为一个因素。
我们对两者都使用 grails 3.5.1。
调试 我已经在 unix 机器和 windows 机器上扩展了 grails 生成的 WAR 文件,默认情况下它在 WEB-INF/lib 中不包含大量 JAR 依赖项,但没有抱怨。我通过在 Config.groovy 中设置 JAR 依赖项来添加这些内容,因此它们现在存在,但构建的 WEB-INF/classes 似乎有所不同。
想法不足 - 任何建议将不胜感激。
在 UNIX 上构建的 grails 命令: <代码>
grails -Dgrails.env=envName war OUR.WAR
完整的堆栈跟踪是: <代码>
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 'lobHandlerDetector' while setting bean property 'lobHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandlerDetector': 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 (Io exception: Invalid number format for port number)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
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 'lobHandlerDetector' while setting bean property 'lobHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandlerDetector': 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 (Io exception: Invalid number format for port number)
... 5 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'lobHandlerDetector' while setting bean property 'lobHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandlerDetector': 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 (Io exception: Invalid number format for port number)
... 5 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandlerDetector': 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 (Io exception: Invalid number format for port number)
... 5 more
Caused by: org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Io exception: Invalid number format for port number)
... 5 more
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Io exception: Invalid number format for port number)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1225)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
at $Proxy22.getMetaData(Unknown Source)
... 5 more
Caused by: java.sql.SQLException: Io exception: Invalid number format for port number
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:255)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
at oracle.jdbc.driver.PhysicalConnection.(PhysicalConnection.java:439)
at oracle.jdbc.driver.T4CConnection.(T4CConnection.java:165)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
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)
... 7 more
令人烦恼的是,所有 java/maven 构建都是简单的迁移 - 但 grails 使用 ivy 而不是 maven - 希望 vmware/springsource 人员将来能够提供完整的 Maven 集成,从而消除这些困难。
但现在任何帮助都会很棒 - 或者对其他要调试的东西的建议
Strange problem - we build a grails project on windows and it works fine, but on a unix machine getting:
java.sql.SQLException: Io exception: Invalid number format for port number (stack trace below)
Pretty strange as we define the datasource to come from jndi:
DataSource.groovy:
envName { dataSource { dbCreate = "none" jndiName = "java:comp/env/jdbc/ourDataSource" dialect="org.hibernate.dialect.Oracle10gDialect" }
The jndi is handled by a setting in context.xml on the application server:
<Resource name="jdbc/ourDataSource" auth="Container" type="javax.sql.DataSource" username="OUR_DB_USERNAME" password="OUR_DB_PASSWORD" driverClassName="oracle.jdbc.OracleDriver" url="jdbc:oracle:thin:@host:1521:sid" maxActive="8" maxIdle="4"/>
We would expect the build to be environment agnostic. Examining the deltas:
Both are using slightly different versions of the JDK - 1.6.0_21 on unix, 1.6.0_22 on windows. Assume this wouldn't be a factor.
We are using grails 3.5.1 for both.
Debugging I've expanded WAR files generated by grails on the unix machine and on the windows machine and by default it didn't include lots of JAR dependencies in WEB-INF/lib but without complaint. I added these by setting a JAR dependency in Config.groovy so they are now present but the build WEB-INF/classes seem to differ.
Running low on ideas - any suggestions would be much appreciated.
grails command to build on unix:
grails -Dgrails.env=envName war OUR.WAR
Full stacktrace is:
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 'lobHandlerDetector' while setting bean property 'lobHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandlerDetector': 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 (Io exception: Invalid number format for port number) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662) 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 'lobHandlerDetector' while setting bean property 'lobHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandlerDetector': 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 (Io exception: Invalid number format for port number) ... 5 more Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'lobHandlerDetector' while setting bean property 'lobHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandlerDetector': 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 (Io exception: Invalid number format for port number) ... 5 more Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandlerDetector': 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 (Io exception: Invalid number format for port number) ... 5 more Caused by: org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Io exception: Invalid number format for port number) ... 5 more Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Io exception: Invalid number format for port number) at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1225) at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880) at $Proxy22.getMetaData(Unknown Source) ... 5 more Caused by: java.sql.SQLException: Io exception: Invalid number format for port number at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:255) at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387) at oracle.jdbc.driver.PhysicalConnection.(PhysicalConnection.java:439) at oracle.jdbc.driver.T4CConnection.(T4CConnection.java:165) at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35) at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801) 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) ... 7 more
Annoyingly all the java/maven builds have been straightforward migrations - but grails uses ivy rather than maven - hopefully the vmware/springsource guys will provide full maven integration in future negating these sorts of difficulties.
But any help now would be great - or suggestions for other things to debug
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案:添加java.sql.SQLException断点
我已经解决了这个问题。在 Eclipse 中在 java.sql.SQLException 上添加了断点。通过堆栈查找,它在 DataSource.groovy 中发现了错误的配置;反过来,Hudson 中的 -Dgrails.env 参数没有被采纳。痛苦。
Solution: add java.sql.SQLException breakpoint
I've solved this. In eclipse added breakpoint on java.sql.SQLException. Looking up through the stack it had picked up the wrong configuration in DataSource.groovy; in turn the -Dgrails.env argument in Hudson was not being picked up. Painful.