package cn.autoform.fw.config; import com.zaxxer.hikari.HikariDataSource; import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; import javax.sql.DataSource; import java.sql.SQLException; @Configuration public class DataSourceConfig { @Bean public DataSource dataSource(Environment environment) throws SQLException { RelaxedPropertyResolver propertyResolver = new RelaxedPropertyResolver(environment, "spring.datasource."); HikariDataSource ds = new HikariDataSource(); ds.setUsername(propertyResolver.getProperty("username")); ds.setJdbcUrl(propertyResolver.getProperty("url")); ds.setDriverClassName(propertyResolver.getProperty("driver-class-name")); ds.setPassword(propertyResolver.getProperty("key")); ds.setReadOnly(false); ds.setConnectionTimeout(60000); ds.setIdleTimeout(60000); ds.setValidationTimeout(5000); ds.setMaxLifetime(60000); ds.setLoginTimeout(5); ds.setMaximumPoolSize(60); ds.setMinimumIdle(10); return ds; } }