SpringBoot-配置文件属性注入-2

SpringBoot-配置文件属性注入-2

标签(空格分隔): java,SpringBoot

1.创建配置文件[application.properties]

SpringBoot-配置文件属性注入-2

2.创建JdbcConfig类

package com.itheima.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

@Configuration
public class JdbcConfig {

    @Bean
    @ConfigurationProperties(prefix = "jdbc")
    public DataSource dataSource() {
        DruidDataSource druidDataSource = new DruidDataSource();
        return druidDataSource;
    }
}

3.Debug运行测试

SpringBoot-配置文件属性注入-2

上一篇:spring boot druid数据源配置


下一篇:基于springboot通过注解AOP动态切换druid多数据源--mybatis