springboot2 在已经配置了数据源的url情况下仍报url未配置问题

项目在application.yml 或 application.properties文件已经配置了spring.datasource.url数据库信息情况下,

启动仍报:

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

Reason: Failed to determine suitable jdbc url


Action:

Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a partic

 

检查pom文件里面 有没有打包成pom

<packaging>pom</packaging>

有的话去掉  

 

  • 11
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
在Spring Boot中使用Nacos配置多个数据源的步骤如下: 1. 在Nacos控制台中创建两个配置文件,分别对应两个数据源配置信息。例如: ``` # 数据源1配置 datasource1.url=jdbc:mysql://localhost:3306/db1 datasource1.username=root datasource1.password=123456 # 数据源2配置 datasource2.url=jdbc:mysql://localhost:3306/db2 datasource2.username=root datasource2.password=123456 ``` 2. 在Spring Boot的配置文件中引入Nacos配置中心的依赖,并配置Nacos Server的地址和命名空间。 ``` spring.cloud.nacos.config.server-addr=localhost:8848 spring.cloud.nacos.config.namespace=your-namespace ``` 3. 创建两个数据源配置类,分别读取对应的Nacos配置文件中的数据源配置信息。 ```java @Configuration @RefreshScope public class DataSource1Config { @Value("${datasource1.url}") private String url; @Value("${datasource1.username}") private String username; @Value("${datasource1.password}") private String password; @Bean(name = "dataSource1") public DataSource dataSource1() { return DataSourceBuilder.create() .url(url) .username(username) .password(password) .build(); } } @Configuration @RefreshScope public class DataSource2Config { @Value("${datasource2.url}") private String url; @Value("${datasource2.username}") private String username; @Value("${datasource2.password}") private String password; @Bean(name = "dataSource2") public DataSource dataSource2() { return DataSourceBuilder.create() .url(url) .username(username) .password(password) .build(); } } ``` 4. 在使用数据源的地方,通过@Qualifier注解指定对应的数据源。 ```java @Service public class UserService { @Autowired @Qualifier("dataSource1") private DataSource dataSource1; @Autowired @Qualifier("dataSource2") private DataSource dataSource2; // 使用dataSource1和dataSource2进行数据库操作 } ``` 5. 在Nacos控制台中修改数据源配置后,使用@RefreshScope注解实现配置的动态更新。 ```java @RefreshScope @Configuration public class DataSource1Config { // ... } @RefreshScope @Configuration public class DataSource2Config { // ... } ``` 以上就是在Spring Boot中使用Nacos配置多个数据源的步骤。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值