天天看點

java建立資料源_JAVA建立資料源(JdbcTemplate)

//

//Source code recreated from a .class file by IntelliJ IDEA//(powered by Fernflower decompiler)//

packageorg.springframework.boot.autoconfigure.jdbc;importjavax.sql.DataSource;importorg.springframework.boot.autoconfigure.AutoConfigureAfter;importorg.springframework.boot.autoconfigure.condition.ConditionalOnClass;importorg.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;importorg.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;importorg.springframework.context.annotation.Bean;importorg.springframework.context.annotation.Configuration;importorg.springframework.context.annotation.Primary;importorg.springframework.jdbc.core.JdbcOperations;importorg.springframework.jdbc.core.JdbcTemplate;importorg.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;importorg.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;

@Configuration

@ConditionalOnClass({DataSource.class, JdbcTemplate.class})

@ConditionalOnSingleCandidate(DataSource.class)

@AutoConfigureAfter({DataSourceAutoConfiguration.class})public classJdbcTemplateAutoConfiguration {private finalDataSource dataSource;publicJdbcTemplateAutoConfiguration(DataSource dataSource) {this.dataSource =dataSource;

}

@Bean

@Primary

@ConditionalOnMissingBean({JdbcOperations.class})publicJdbcTemplate jdbcTemplate() {return new JdbcTemplate(this.dataSource);

}

@Bean

@Primary

@ConditionalOnMissingBean({NamedParameterJdbcOperations.class})publicNamedParameterJdbcTemplate namedParameterJdbcTemplate() {return new NamedParameterJdbcTemplate(this.dataSource);

}

}