时间:2021-07-01 10:21:17 帮助过:20人阅读
package com.caicia.config;
import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import javax.sql.DataSource;
@Configuration
@EnableConfigurationProperties(jdbcProperties.class)
@PropertySource("classpath:jdbc.properties") 以前的配置方式
public class JdbcConfig {
//Spring boot 自带的Value注解
@Value("${jdbc.url}")
String url;
@Value("${jdbc.driverClassName}")
String dirclassname;
@Value("${jdbc.username}")
String username;
@Value("${jdbc.password}")
String password;
@Bean
public DataSource dataSource(){
DruidDataSource dataSource = new DruidDataSource();
dataSource.setDriverClassName(dirclassname);
dataSource.setUsername(username);
dataSource.setUrl(url);
dataSource.setPassword(password);
return dataSource;
}
}
Spring Boot 配置数据库 连接方式
标签:actor ring spring mysq @Value source div mys contex