手写一个bean即可
import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.PropertySource;
import org.springframework.core.env.StandardEnvironment;
import javax.sql.DataSource;
import java.util.Map;
import java.util.Properties;
@Configuration
public class DataSourceConfig {
@Value("${spring.datasource.druid.url}")
String url;
@Value("${spring.datasource.druid.username}")
String username;
@Value("${spring.datasource.druid.password}")
String password;
@Value("${spring.datasource.druid.driver-class-name}")
String driverClassName;
@Bean
public DruidDataSource druidDataSource() {
DruidDataSource dataSource = new DruidDataSource();
// Configure DruidDataSource properties
dataSource.setUrl(url);
dataSource.setUsername(username);
dataSource.setPassword(password);
dataSource.setDriverClassName(driverClassName);
// Add additional configurations if needed
return dataSource;
}
}