标签:actor ring spring mysq @Value source div mys contex
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/leyou
jdbc.username=root
jdbc.password=123456
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;
}
}
标签:actor ring spring mysq @Value source div mys contex
原文地址:https://www.cnblogs.com/caicai920/p/14961114.html