1.SpringBoot默认数据源测试

  • SpringBoot2默认数据源:HikariCP
  • 本文采用SpringBoot 2.1.2.RELEASE版本

1.导入依赖



    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.1.2.RELEASE
        
    
    com.etoak.springboot
    springboot-default-datasource
    0.0.1-SNAPSHOT

    
        1.8
    

    
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.springframework.boot
            spring-boot-starter-jdbc
        
        
            mysql
            mysql-connector-java
            runtime
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
    
    
    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    

2.配置application.properties

#
server.port=9090
server.servlet.context-path=/jdbc

# jdbc--
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test?serverTimezone=GMT
spring.datasource.username=root
spring.datasource.password=123456

3.编写测试类

@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringbootJdbcApplicationTests {

    @Autowired
    DataSource dataSource;

    @Test
    public void contextLoads() {
        System.out.println("====>" + dataSource);
    }
}

4.结果

====>HikariDataSource

你可能感兴趣的:(1.SpringBoot默认数据源测试)