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

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

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

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

SpringBoot-Properties配置文件属性注入-2_第1张图片

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-Properties配置文件属性注入-2_第2张图片

你可能感兴趣的:(SpringBoot-Properties配置文件属性注入-2)