区分基于XML的配置方式和基于注解的配置方式

mybatis学习过程中遇到下面的bugCause: java.io.IOException: Could not find resource com.itheima.dao.IUserDao.xml网上有在pom.xml中加配置内容的,但并没有解决我的bug。通过仔细检查代码,原来是路径内容错误,不知道该用斜杠/还是 点.来划分

基于XML的配置方式:1e8f3eaa91b5425993748344331e09e4.jpg

 

基于注解的配置方式:

61ca8791b5db4db1a10994570b7b6464.jpg

 

一定要注意:

resource="com/itheimaF/IUserDao.xml"和

class="com.itheima.dao.IUserDao"对应正确后,测试通过:bca4d1d924784a3ea4b5bb8baddafc73.jpg

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Java Spring Boot中,YAML(Yet Another Markup Language)是一种简洁的配置文件格式,用于替代XML配置。Spring Boot通过Spring Boot Actuator提供对YAML的支持,使得配置管理更加直观和易读。 以下是使用Spring Boot配置YAML的基本步骤: 1. **创建YAML配置文件**: 在`src/main/resources`目录下创建一个名为`application.yml`或`application.properties`(默认为properties格式,但Spring Boot也支持YAML)的文件。例如,对于YAML配置: ```yaml server: port: 8080 spring: datasource: url: jdbc:mysql://localhost:3306/mydb username: user password: pass ``` 2. **引用配置**: 在主应用类上添加`@SpringBootApplication`注解,并启用YAML加载,可以通过`spring.config.location`属性指定配置文件位置,如`spring.config.location=classpath:application.yml`。 ```java import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ConfigurationProperties; @SpringBootApplication @ConfigurationProperties(prefix = "spring.datasource") public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } ``` 3. **使用配置属性**: 使用@ConfigurationProperties注解可以自动将YAML中的键值对映射到Java类的属性上,使得配置更易于管理和使用。 4. **使用Profile(环境变量)**: Spring Boot支持基于环境的配置,可以在YAML中定义不同的环境模式,如`application-dev.yml`、`application-prod.yml`等,通过`spring.profiles.active`属性切换环境。 相关问题-- 1. Spring Boot如何区分YAML和properties配置? 2. 如何在Spring Boot中启用YAML配置并指定文件路径? 3. 什么情况下会使用Spring Boot的Profile功能?

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值