Skip to content

Instantly share code, notes, and snippets.

@arijit83sarkar
Last active May 21, 2023 18:56
Show Gist options
  • Save arijit83sarkar/8983bdd42fe9202b9bcd2b849758518e to your computer and use it in GitHub Desktop.
Save arijit83sarkar/8983bdd42fe9202b9bcd2b849758518e to your computer and use it in GitHub Desktop.
How To Use JDBCTemplate In Spring Boot With Swagger OpenAPI
package com.raven.jdbctemplate.config;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import javax.sql.DataSource;
@Configuration
public class ApplicationConfiguration {
@Bean(name = "dataSource")
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
@Bean(name = "jdbcTemplate")
public JdbcTemplate jdbcTemplate1(@Qualifier("dataSource") DataSource ds) {
return new JdbcTemplate(ds);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment