IDEA下maven的mapper.xml檔案路徑改為resources資料夾下
阿新 • • 發佈:2018-12-16
在IDEA下建立maven專案時, 使用SSM框架,需要把mapper.xml 檔案放在resources資料夾下,這樣target資料夾才有mapper.xml檔案,否則是沒有的.
相關配置檔案:
application-dao.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd " >
<!-- 載入db.properties檔案中的內容,db.properties檔案中key命名要有一定的特殊規則 -->
<context:property-placeholder location="classpath:db.properties" />
<!-- 配置資料來源 ,dbcp -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<!-- 驅動 -->
<property name="driverClassName" value="${jdbc.driver}" />
<!-- url -->
<property name="url" value="${jdbc.url}" />
<!-- 使用者名稱 -->
<property name="username" value="${jdbc.username}" />
<!-- 密碼 -->
<property name="password" value="${jdbc.password}" />
</bean>
<!-- sqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 資料庫連線池 -->
<property name="dataSource" ref="dataSource" />
<!--自動掃描mapper.xml檔案-->
<property name="mapperLocations" value="classpath:mapper/*.xml"/>
<!-- 載入mybatis的全域性配置檔案 -->
<property name="configLocation" value="classpath:mybatis/sqlMapConfig.xml" />
</bean>
<!-- mapper掃描器 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 掃描包路徑,如果需要掃描多個包,中間使用半形逗號隔開 -->
<property name="basePackage" value="com.jzt.ssm.mapper"></property>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>
</beans>