springboot maven资源路径配置 resource路径配置, 解决mybatis的xml放在java路径而没有放在resource路径下报错的问题

 

 

 

 

 

 

我是这样配置的

 

 

<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);
   }
}
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值