在Spring3.0环境中,我将从iBatis 2迁移到MyBatis 3。当我试图部署应用程序,甚至只是运行JUnit测试时,配置初始化会失败,出现连接超时错误,如下所示:
在类路径资源testContext-jndi.xml中定义了名为“sqlSessionFactory”的bean创建错误: init方法调用失败;嵌套的异常是org.apache.ibatis.builder.BuilderException: Error创建文档实例。原因: java.net.ConnectException:连接超时:连接
它看起来像是一个缺失的http代理,但是我的eclipse代理设置总是适用于我的所有其他代码。我的DTD定义似乎是正确的。
我正在使用Spring3.0.0,并在我的类路径中包含了以下jars:
相关的spring配置如下:
fooContext-data.xml -(这是测试/资源配置。当部署到web容器时,春季配置的数据源使用JNDI查找来获取凭据。他们都以同样的方式失败。)
<?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>
<!-- MyBatis stuff -->
<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>sqlMapConfig.xml
<?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>我注意到其他一些人也有这个问题,这与myBatis xml的DTD有问题,或者网络连接不好有关,从而阻止了DTD定义的取消。我看不出我怎么会有这个问题,因为我的方案中似乎涵盖了所有这些基础。
我在这个问题上已经讨论了一天半了,我已经破坏了MyBatis和MyBatis的文档,以及这个站点和其他网站的一些内容。任何想法都将不胜感激。
发布于 2013-08-13 19:53:08
我在myBatis用户站点上找到了这个问题的答案:www.mybatis.org关闭时的DTD验证
原来我的DTD链接不应该有www在他们前面。也就是说,而不是:
<!DOCTYPE configuration
PUBLIC "-//www.mybatis.org//DTD Config 3.0//EN"
"http://www.mybatis.org/dtd/mybatis-3-config.dtd">他们应该读到:
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">我改变了这些,现在起作用了。
https://stackoverflow.com/questions/18154667
复制相似问题