测试6miu的博客到底好用不好用

xiaoxiao2021-02-28  93

这里是正文

package com.xxx; import java.sql.SQLException; import javax.sql.DataSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import com.alibaba.druid.pool.DruidDataSource; @Configuration @EnableConfigurationProperties(DruidProperties.class) @ConditionalOnClass(DruidDataSource.class) @ConditionalOnProperty(prefix = "druid", name = "url") @AutoConfigureBefore(DataSourceAutoConfiguration.class) public class DruidAutoConfiguration { private Logger logger = LoggerFactory.getLogger(this.getClass()); @Autowired private DruidProperties properties; @Bean public DataSource dataSource() { DruidDataSource dataSource = new DruidDataSource(); dataSource.setUrl(properties.getUrl()); dataSource.setUsername(properties.getUsername()); dataSource.setPassword(properties.getPassword()); if (properties.getInitialSize() > 0) { dataSource.setInitialSize(properties.getInitialSize()); } if (properties.getMinIdle() > 0) { dataSource.setMinIdle(properties.getMinIdle()); } if (properties.getMaxActive() > 0) { dataSource.setMaxActive(properties.getMaxActive()); } dataSource.setTestOnBorrow(properties.isTestOnBorrow()); try { dataSource.init(); } catch (SQLException e) { throw new RuntimeException(e); } logger.info("阿里巴巴数据库连接池[druid]启动中..."); return dataSource; } } 下面已经不是代码片段了。

转载请注明原文地址: https://www.6miu.com/read-76903.html

最新回复(0)