今日练习:springBoot使用默认的数据源hikariDataSource

在application配置文件中配置DataSource的属性
yaml格式:

spring: 
 datasource: 
  url: jdbc:mysql://localhost:3306/miduoduo?useSSL=false&serverTimezone=UTC&characterEncoding=utf-8
  password: 123456
  driver-class-name: com.mysql.cj.jdbc.Driver
  username: root

properties格式:

spring.datasource.url=jdbc:mysql://localhost:3306/miduoduo?useSSL=false&serverTimezone=UTC&characterEncoding=utf-8
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root

获取datasource测试类

@Controller
public class JDBCController {
     
@Autowired
private DataSource dataSource;
@RequestMapping("/jdbc")
public void jdbc() {
     
	try {
     
		System.out.println(dataSource.getConnection());
	} catch (SQLException e) {
     
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
	
}
}

spring.datasource.type可以更改数据源

你可能感兴趣的:(今日份代码,jdbc)