springboot maven資源路徑配置 resource路徑配置, 解決mybatis的xml放在java路徑而沒有放在resource路徑下報錯的問題
阿新 • • 發佈:2019-02-14
我是這樣配置的
<build> <!--resources配置解決mybatis 的mapperXml配置在java路徑不被掃描的問題 --> <resources> <resource> <directory>src/main/java</directory> </resource> <resource> <directory>src/main/resources</directory> </resource> </resources> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <!--跳過測試 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skipTests>true</skipTests> </configuration> </plugin> </plugins> </build> </project>
然後在資原始檔 application.properites裡面配置mybatis的xml路徑
server.port=8081 #必須有 mybatis.mapper-locations=classpath*:com/hanhan/dao/xmlMapper/*.xml #必須有 logging.config=classpath:logback.xml #必須有 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver #必須有 spring.datasource.url=jdbc:mysql://127.0.0.1:3307/ipace?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=CTT #必須有 spring.datasource.username=root #必須用 spring.datasource.password=root #32位隨機字串 #dd9008e5ec8608c9eb9d57ab764651eb rand.str = ${random.value} #36位,比32位的多了4個- #0cf88531-9569-44c4-926e-2528dd5948e2 rand.uuid = ${random.uuid} #隨機int型別,主意有負數 rand.intid = ${random.int} #隨機long型別 rand.longid = ${random.long} #100以內的隨機int型別 rand.number = ${random.int(100)} #0-10億範圍內的隨機int型別 rand.range = ${random.int[0,1000000000]}
java的介面mapper路徑掃描在啟動類上配置
import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.scheduling.annotation.EnableScheduling; @SpringBootApplication(scanBasePackages = {"com.hanhan","hanhan"}) @MapperScan({"com.hanhan.dao"}) @EnableScheduling public class BeetltestApplication { public static void main(String[] args) { SpringApplication.run(BeetltestApplication.class, args); } }