初步搭建springboot应用,报错:Failed to configure a DataSource: 'url' attribute is not specified and no embedd

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

翻译就是:无法配置DataSource:未指定'url'属性,也无法配置嵌入数据源。

很明显,就是你在应用中没有配置datasource的一些相关属性,例如:地址值啊,数据库驱动啊,用户名啊,密码啊,

都知道,SpringBoot的最大一个好处就是自动配置:所以我们只是需要给他配置文件的值,它就会自动配置。配置在application.properties文件中

那么我将把SpringBoot的一些最基本的配置信息给大家站出来:


  
  
  1. #访问根路径
  2. #应用名称
  3. spring.application.name=springboot-demo
  4. #访问端口号
  5. server.port=8080
  6. #编码格式
  7. server.tomcat.uri-encoding=utf-8
  8. #数据库相关配置
  9. spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
  10. spring.datasource.url=jdbc:mysql://localhost:3306/sql_test
  11. spring.datasource.username=root
  12. spring.datasource.password=123456
  13. spring.datasource.max-idle=10
  14. spring.datasource.max-wait=10000
  15. spring.datasource.min-idle=5
  16. spring.datasource.initial-size=5
  17. #session生命周期
  18. server.servlet.session.timeout=30m

当然,也可以不配置,但是你需要声明一下

扫描二维码关注公众号,回复: 10735890 查看本文章

启动类头部声明就可以了:

@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
  
  
发布了244 篇原创文章 · 获赞 2 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_44813090/article/details/105268537
今日推荐