I have having this exact same issue. I am using Spring 3.0.0 and the
following mybatis jars are in my classpath:
mybatis-3.2.2.jar
mybatis-spring-1.2.0.jar
-----------------------------------------------------------------------------------------------------
The same error occurs whether I am running a JUnit test or deploying the
application to a web container:
Error creating bean with name 'sqlSessionFactory' defined in class path
resource [testContext-jndi.xml]: Invocation of init method failed; nested
exception is org.apache.ibatis.builder.BuilderException: Error creating
document instance. Cause: java.net.ConnectException: Connection timed out:
connect
-----------------------------------------------------------------------------------------------------
I know the database credentials are good. They have not changed in years.
They work with iBatis 2. When deploying to web container, the data source
uses a JNDI lookup to gather the credentials from the server. In the unit
test environment they're in the Spring file itself. This is the relevant
part of my test/resources configuration:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"
http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="dataSourceFoo" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close" >
<property name="driverClassName" value="oracle.jdbc.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@(DESCRIPTION =
(LOAD_BALANCE=on)(FAILOVER=on)(ADDRESS=(PROTOCOL=tcp)(HOST=foo1)(PORT=1521))(ADDRESS=(PROTOCOL=tcp)(HOST=foo2)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=foo.bar.boz)))"/>
<property name="username" value="fooUser"/>
<property name="password" value="fooPass"/>
</bean>
<bean id="sqlSessionFactory"
class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSourceFoo" />
<property name="configLocation" value="sqlMapConfig.xml" />
</bean>
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory" />
</bean>
</beans>
-----------------------------------------------------------------------------------------------------
Here is my sqlMap config:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//
www.mybatis.org//DTD Config 3.0//EN"
"
http://www.mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<properties resource="ibatis.properties" />
<mappers>
<mapper resource="foo/dao/maps/mybatis/SqlMap1.xml"/>
<mapper resource="foo/dao/maps/mybatis/SqlMap2.xml"/>
<mapper resource="foo/dao/maps/mybatis/SqlMap3.xml"/>
<mapper resource="foo/dao/maps/mybatis/SqlMap4.xml"/>
<mapper resource="foo/dao/maps/mybatis/SqlMap5.xml"/>
<mapper resource="foo/dao/maps/mybatis/SqlMap6.xml"/>
<mapper resource="foo/dao/maps/mybatis/SqlMap7.xml"/>
<mapper resource="foo/dao/maps/mybatis/SqlMap8.xml"/>
<mapper resource="foo/dao/maps/mybatis/SqlMap9.xml"/>
<mapper resource="foo/dao/maps/mybatis/SqlMap10.xml"/>
<mapper resource="foo/dao/maps/mybatis/SqlMap11.xml"/>
<mapper resource="foo/dao/maps/mybatis/SqlMap12.xml"/>
<mapper resource="foo/dao/maps/mybatis/SqlMap13.xml"/>
<mapper resource="foo/dao/maps/mybatis/SqlMap14.xml"/>
<mapper resource="foo/dao/maps/mybatis/SqlMap15.xml"/>
</mappers>
</configuration>
----------------------------------------------------------------------------------------------------
All of the DAO and sqlMap wiring seems to be happening without a problem.
I noticed that some others were having this problem, and it was related to
something being wrong with the DTD of the myBatis xml, or having a bad
network connection, preventing them from pulling down the DTD definition. I
do not have this problem, and have removed ALL of my old iBatis 2 jars,
files, classes, etc. to make sure there is not a strange conflict between
the two versions.
Is there a compatibility problem with MyBatis 3.2.2, and Spring 3.0.0? I've
been at this problem for a day and a half, having scourged the documentation
for both MyBatis, and MyBatis-Spring, as well as a good bit of this site and
others. Any ideas would be appreciated.
--
View this message in context:
http://mybatis-user.963551.n3.nabble.com/Connection-time-out-error-tp4026924p4027255.html