classpath* 這個星加上便可,很是重要,在這裏踩了兩次坑,記錄一下html
mybatis: config-location: classpath:mybatis/mybatis.cfg.xml # mybatis配置文件所在路徑 mapper-locations: - classpath*:com/example/demo/**/dao/xml/*.xml # mapper映射文件
在pom.xml 加入以下配置便可(跳過測試打包:clean package -Dmaven.test.skip=true )java
<build> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> </resource> </resources> </build>
<build> <resources> <!-- 若是不加,那麼打包的時候mapper文件不會被加載進來 --> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> </resources> </build>
直接右鍵點擊包 -> Mark Directory As ,你會發現只有一個exclude;怎麼辦?nginx
Project Structure -> Modules -> Sources -> 選擇包含配置文件的package -> Mark as -> 選擇第三個 Resources -> OKmybatis
參考:http://stackoverflow.com/questions/6104551/java-setting-classpathapp