关于mybatis问题,请高手进
我目前使用struts2+spring+mybatis进行开发,在进行mybatis配置的时候出现了一下问题:
我在applicationContext.xml进行了如下定义:
<!-- IBATIS -->
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="WEB-INF/sqlMapConfig.xml" />
<property name="dataSource" ref="dataSource" />
</bean>
在sqlMapConfig.xml中,进行了如下定义:
<sqlMapConfig>
<settings useStatementNamespaces="true" cacheModelsEnabled="true" lazyLoadingEnabled="true" enhancementEnabled="true" />
<sqlMap resource="WEB-INF/userMap.xml" />
</sqlMapConfig>
在userMap.xml中,进行了如下定义:
<sqlMap>
<typeAlias type="org.struts2.dao.User" alias="user"/>
<resultMap id="UserTest" class="user" >
<result column="username1" property="username1" jdbcType="VARCHAR" />
<result column="password" property="password" jdbcType="VARCHAR" />
</resultMap>
<select id="select" resultMap="UserTest">
select * from t_user
</select>
</sqlMap>
问题:我在启动tomcat的时候,出现了以下问题:
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sqlMapClient' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is
org.springframework.core.NestedIOException: Failed to parse config resource: ServletContext resource [/WEB-INF/sqlMapConfig.xml]; nested exception is com.ibatis.common.xml.NodeletException: Error parsing XML. Cause:
java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'. Cause:
java.io.IOException: Could not find resource WEB-INF/userMap.xml
注:我已经确认了,在
WEB-INF/的路径下,确实存在userMap.xml,但是为什么还是找不到呢?
------解决方案--------------------不要放在web-inf下 放在src目录下 比如建个sqlMap文件夹
------解决方案--------------------