SpringMVC + mybatis 无法读取JAR包中的XML配置文件问题
2016-11-28 12:01
1071 查看
SpringMVC + mybatis 无法读取JAR包中的XML配置文件问题
在进行SpringMVC+Mybatis进行整合时,如果Mybatis的XML配置文件存在于JAR包中,当工程运行时会报出找不到方法异常。
如:
<bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="datasource"></property>
<property name="mapperLocations">
<array>
<value>classpath:com/sdzn/*/dao/xml/*.xml</value>
</array>
</property>
</bean>
虽然正常情况下是可以读取XML配置文件的,但如果将工程打成JAR包,发布出去,在新工程中进行引用时,就会出现找不到XML配置文件的情况
因此我们需要将配置文件做一个修改
<bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="datasource"></property>
<property name="mapperLocations">
<array>
<value>classpath*:com/sdzn/*/dao/xml/*.xml</value>
</array>
</property>
</bean>
即在classpath后面加一个*号。意义是读取JAR中的XML文件
在进行SpringMVC+Mybatis进行整合时,如果Mybatis的XML配置文件存在于JAR包中,当工程运行时会报出找不到方法异常。
如:
<bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="datasource"></property>
<property name="mapperLocations">
<array>
<value>classpath:com/sdzn/*/dao/xml/*.xml</value>
</array>
</property>
</bean>
虽然正常情况下是可以读取XML配置文件的,但如果将工程打成JAR包,发布出去,在新工程中进行引用时,就会出现找不到XML配置文件的情况
因此我们需要将配置文件做一个修改
<bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="datasource"></property>
<property name="mapperLocations">
<array>
<value>classpath*:com/sdzn/*/dao/xml/*.xml</value>
</array>
</property>
</bean>
即在classpath后面加一个*号。意义是读取JAR中的XML文件
相关文章推荐
- SpringMVC + mybatis 无法读取JAR包中的XML配置文件问题
- SpringMVC + mybatis 无法读取JAR包中的XML配置文件问题
- SpringMVC + mybatis 无法读取JAR包中的XML配置文件问题
- 关于Spring与mybatis整合无法读取配置文件的问题
- SSM:spring+springmvc+mybatis框架中的XML配置文件功能详细解释
- Spring+Mybatis整合读取Jar中的mapper配置文件
- 整合SpringMVC+Spring+Mybatis+mysql的maven配置文件pom.xml
- SSM:spring+springmvc+mybatis框架中的XML配置文件功能详细解释
- springMVC+MyBatis+meaven整合的pom.xml配置文件
- maven多模块Springmvc+mybatis读取配置文件和注入bean
- spring+springMVC+mybatis整合示例(基于XML配置文件)
- SSM:spring+springmvc+mybatis框架中的XML配置文件功能详细解释
- SSM:spring+springmvc+mybatis框架中的XML配置文件功能详细解释
- SSM:spring+springmvc+mybatis框架中的XML配置文件功能详细解释
- 基于maven管理的项目中spring+mybatis配置数据源读取不到properties属性文件的问题
- SSM:spring+springmvc+mybatis框架中的XML配置文件功能详细解释
- Springmvc+mybatis的定时器配置文件spring-quartz.xml
- ssm spring+springmvc+mybatis中的xml配置文件详解
- Spring配置文件打包到jar中无法加载问题之解决方案
- SSM:spring+springmvc+mybatis框架中的XML配置文件功能详细解释