title: MyBatis-Spring: SqlSessionFactoryBean initialization: connection timeout
body: <p>I am migrating from iBatis 2 to MyBatis 3 in a Spring 3.0 environment.  When I attempt to deploy the application, or even just run a JUnit test, the config initialization fails with a connection timeout error as follows: </p>
  
  <blockquote>
    <p>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</p>
  </blockquote>
  
  <p>It looks like a missing http proxy, but my eclipse proxy settings have always worked for all my other code.  My DTD definitions appear to be correct.  </p>
  
  <p>I am using Spring 3.0.0, and have included the following jars in my classpath: </p>
  
  <ul>
  <li>mybatis-3.2.2.jar</li>
  <li>mybatis-spring-1.2.0.jar  </li>
  </ul>
  
  <p>The relevant spring configuration is as follows:</p>
  
  <p>fooContext-data.xml - (this is the test/resources configuration.  When deploying to a web container, the spring-configured data source uses a JNDI lookup to get credentials.  They both fail the same way.)</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"&gt;
  
  &lt;beans&gt;
  
      &lt;bean id="dataSourceFoo" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" &gt;
          &lt;property name="driverClassName" value="oracle.jdbc.OracleDriver"/&gt;
          &lt;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)))"/&gt;
          &lt;property name="username" value="fooUser"/&gt;
          &lt;property name="password" value="fooPass"/&gt;             
      &lt;/bean&gt;
  
      &lt;!-- MyBatis stuff --&gt;
      &lt;bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSourceFoo" /&gt;
          &lt;property name="configLocation" value="sqlMapConfig.xml" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate"&gt;
          &lt;constructor-arg index="0" ref="sqlSessionFactory" /&gt;
      &lt;/bean&gt;
  
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>sqlMapConfig.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE configuration
          PUBLIC "-//www.mybatis.org//DTD Config 3.0//EN"
          "http://www.mybatis.org/dtd/mybatis-3-config.dtd"&gt;
  
  &lt;configuration&gt;
  
      &lt;properties resource="ibatis.properties" /&gt;
  
      &lt;mappers&gt;
          &lt;mapper resource="foo/dao/maps/mybatis/SqlMap1.xml"/&gt;
          &lt;mapper resource="foo/dao/maps/mybatis/SqlMap2.xml"/&gt;
          &lt;mapper resource="foo/dao/maps/mybatis/SqlMap3.xml"/&gt;
          &lt;mapper resource="foo/dao/maps/mybatis/SqlMap4.xml"/&gt;
          &lt;mapper resource="foo/dao/maps/mybatis/SqlMap5.xml"/&gt;
          &lt;mapper resource="foo/dao/maps/mybatis/SqlMap6.xml"/&gt;
          &lt;mapper resource="foo/dao/maps/mybatis/SqlMap7.xml"/&gt;
          &lt;mapper resource="foo/dao/maps/mybatis/SqlMap8.xml"/&gt;
          &lt;mapper resource="foo/dao/maps/mybatis/SqlMap9.xml"/&gt;
          &lt;mapper resource="foo/dao/maps/mybatis/SqlMap10.xml"/&gt;
          &lt;mapper resource="foo/dao/maps/mybatis/SqlMap11.xml"/&gt;
          &lt;mapper resource="foo/dao/maps/mybatis/SqlMap12.xml"/&gt;
          &lt;mapper resource="foo/dao/maps/mybatis/SqlMap13.xml"/&gt;
          &lt;mapper resource="foo/dao/maps/mybatis/SqlMap14.xml"/&gt;
          &lt;mapper resource="foo/dao/maps/mybatis/SqlMap15.xml"/&gt;
      &lt;/mappers&gt;
  
  &lt;/configuration&gt;
  </code></pre>
  
  <p>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 see how I could have this problem, as all these bases appear to be covered in my scenario.</p>
  
  <p>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.</p>