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

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

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

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

springboot-配置文件.png

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-注入测试.png

posted @ 2020-07-25 16:52  TaylorSWMM  阅读(270)  评论(0编辑  收藏  举报