一、报错信息
首先我这里是通过VPN连接客户那边的数据库,在使用PL/SQL时输入正确的数据库访问地址、用户名和密码可以连接到数据库,但是在使用eclipse启动项目时却报错,报错信息如下:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [jstream-db.xml]: Invocation of init method failed; nested exception is java.sql.SQLException: Io 异常: The Network Adapter could not establish the connection
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
... 57 more
Caused by: java.sql.SQLException: Io 异常: The Network Adapter could not establish the connection
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.<init>(PhysicalConnection.java:414)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
…………
二、定位问题、解决问题
由于在使用eclipse开发时默认使用的是IPv4,所以要在eclipse中添加配置。
1、在eclipse开发工具上添加参数
添加 -Djava.net.preferIPv4Stack=true
开发环境可以连接Oracle数据库,故障解决。
三、总结
在操作系统如果有IPv6环境,应用程序会使用IPV6进行连接。如果只希望应用使用IPv4必须指定修改参数为“ -Djava.net.preferIPv4Stack=true”,