SpringBoot配置jdbc,无法获取DataSource问题。
https://pan.baidu.com/s/1gORkyKH2Ls18_AGzOzrhxg
步骤
1.导入jar包
<dependencies>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
</dependencies>
2.配置jdbc
spring.datasource.url=jdbc:mysql://localhost:3306/springboot
spring.datasource.username=springboot
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
3.测试
ConfigurableApplicationContext context = SpringApplication.run(MainApp.class, args);
System.out.println(context.getBean(DataSource.class));
结果:

请大神指教。
相关推荐
springboot(3) 数据源配置
springboot(3) 数据源配置 请删除项目中本地仓库的配置,或者改成国内的公共仓库,否则将无法启动
Spring boot连接oracle数据库JDBC配置步骤
连接的是oracle 11g,配置成功,查询,更新,都测试成功了
Springboot+MySQL,出现Could not get JDBC Connection
Caused by: org.apache.ibatis.exceptions.PersistenceException: Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO) The error m
SpringBoot多数据源NPE问题解决[源码]
文章描述了在SpringBoot项目中因多数据源配置导致的NullPointerException错误。问题源于自定义JDBC连接池实现了DataSource接口,导致连接池内的数据源信息覆盖了主数据库配置。通过分析,作者指出不应实现DataSource接口以避免此问题。文章提供了错误出现的具体操作步骤、原因分析及解决方案,对遇到类似问题的开发者具有参考价值。
Springboot2.x+ShardingSphere实现分库分表的示例代码
主要介绍了Springboot2.x+ShardingSphere实现分库分表的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧


