测试spring boot中的数据源是否使用的是hikari?
写一个测试类
import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import javax.sql.DataSource; import java.sql.SQLException; /** * @author zhouwenhao * @date 2021/12/1 * @dec 描述 */ @RunWith(SpringRunner.class) @SpringBootTest(classes = MySpringBootApplication.class) public class DataSourceTest { @Autowired private DataSource dataSource; @Test public void testGetConnection() throws SQLException { System.out.println(dataSource.getConnection()); } }
执行后打印结果为:
HikariProxyConnection@575506130 wrapping com.mysql.cj.jdbc.ConnectionImpl@a3cba3a
说明,我们通过dataSource这个对象,获取到了与数据库的连接。这个连接是HikariProxyConnection@575506130。通过它 就可以去访问mysql数据库了。