DataSource를 설정하려면, 스프링 부트에서는 연결 풀이 있거나 H2, HSQLDB, 또는 더비(Derby)등 내장형 데이터베이스가 필요하다.
스프링 부트는 히카리CP나 톰캣 JDBC, 커먼즈 DBCP2 기반의 연결 풀을 순서대로 자동 탐지한다.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
spring-jdbc, spring-tx관련 의존성을 포함하고, 기본 연결 풀은 히카리CP다
내장 데이터 소스 사용
H2, HSQLDB, 더비등을 발견하면 기본적으로 발견하면 기본적으로 발견한 재아 데이터베이스의 내장 연결 풀 구현체를 사용해 기동한다.
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<scope>runtime</scope>
</dependency>
package com.example.demo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import javax.sql.DataSource;
@Slf4j
@Component
public class TableLister implements ApplicationRunner {
private final DataSource dataSource;
public TableLister(DataSource dataSource) {
this.dataSource = dataSource;
}
@Override
public void run(ApplicationArguments args) throws Exception {
try(var con = dataSource.getConnection();
var rs = con.getMetaData().getTables(null,null,"%",null)){
while (rs.next()){
log.info("{}",rs.getString(3));
}
}
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.2.4.RELEASE) 2020-02-13 08:35:22.622 INFO 15228 --- [ restartedMain] com.example.demo.DemoApplication : Starting DemoApplication on DESKTOP-6HPEM1U with PID 15228 (D:\example\springboot2_DB_example1\target\classes started by k in D:\example\springboot2_DB_example1) 2020-02-13 08:35:22.626 INFO 15228 --- [ restartedMain] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default 2020-02-13 08:35:22.684 INFO 15228 --- [ restartedMain] o.s.b.devtools.restart.ChangeableUrls : The Class-Path manifest attribute in C:\Users\k\.m2\repository\org\glassfish\jaxb\jaxb-runtime\2.3.2\jaxb-runtime-2.3.2.jar referenced one or more files that do not exist: file:/C:/Users/k/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/jakarta.xml.bind-api-2.3.2.jar,file:/C:/Users/k/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/txw2-2.3.2.jar,file:/C:/Users/k/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/istack-commons-runtime-3.0.8.jar,file:/C:/Users/k/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/stax-ex-1.8.1.jar,file:/C:/Users/k/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/FastInfoset-1.2.16.jar,file:/C:/Users/k/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/jakarta.activation-api-1.2.1.jar 2020-02-13 08:35:22.684 INFO 15228 --- [ restartedMain] o.s.b.devtools.restart.ChangeableUrls : The Class-Path manifest attribute in C:\Users\k\.m2\repository\org\apache\derby\derby\10.14.2.0\derby-10.14.2.0.jar referenced one or more files that do not exist: file:/C:/Users/k/.m2/repository/org/apache/derby/derby/10.14.2.0/derbyLocale_cs.jar,file:/C:/Users/k/.m2/repository/org/apache/derby/derby/10.14.2.0/derbyLocale_de_DE.jar,file:/C:/Users/k/.m2/repository/org/apache/derby/derby/10.14.2.0/derbyLocale_es.jar,file:/C:/Users/k/.m2/repository/org/apache/derby/derby/10.14.2.0/derbyLocale_fr.jar,file:/C:/Users/k/.m2/repository/org/apache/derby/derby/10.14.2.0/derbyLocale_hu.jar,file:/C:/Users/k/.m2/repository/org/apache/derby/derby/10.14.2.0/derbyLocale_it.jar,file:/C:/Users/k/.m2/repository/org/apache/derby/derby/10.14.2.0/derbyLocale_ja_JP.jar,file:/C:/Users/k/.m2/repository/org/apache/derby/derby/10.14.2.0/derbyLocale_ko_KR.jar,file:/C:/Users/k/.m2/repository/org/apache/derby/derby/10.14.2.0/derbyLocale_pl.jar,file:/C:/Users/k/.m2/repository/org/apache/derby/derby/10.14.2.0/derbyLocale_pt_BR.jar,file:/C:/Users/k/.m2/repository/org/apache/derby/derby/10.14.2.0/derbyLocale_ru.jar,file:/C:/Users/k/.m2/repository/org/apache/derby/derby/10.14.2.0/derbyLocale_zh_CN.jar,file:/C:/Users/k/.m2/repository/org/apache/derby/derby/10.14.2.0/derbyLocale_zh_TW.jar 2020-02-13 08:35:22.685 INFO 15228 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable 2020-02-13 08:35:22.685 INFO 15228 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG' 2020-02-13 08:35:23.336 INFO 15228 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode! 2020-02-13 08:35:23.337 INFO 15228 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JDBC repositories in DEFAULT mode. 2020-02-13 08:35:23.349 INFO 15228 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 9ms. Found 0 JDBC repository interfaces. 2020-02-13 08:35:23.358 INFO 15228 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode! 2020-02-13 08:35:23.358 INFO 15228 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode. 2020-02-13 08:35:23.361 INFO 15228 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 0ms. Found 0 JPA repository interfaces. 2020-02-13 08:35:23.535 INFO 15228 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2020-02-13 08:35:23.789 INFO 15228 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2020-02-13 08:35:23.795 INFO 15228 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2020-02-13 08:35:23.795 INFO 15228 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.30] 2020-02-13 08:35:23.902 INFO 15228 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2020-02-13 08:35:23.903 INFO 15228 --- [ restartedMain] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1218 ms 2020-02-13 08:35:24.026 INFO 15228 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting... 2020-02-13 08:35:24.028 WARN 15228 --- [ restartedMain] com.zaxxer.hikari.util.DriverDataSource : Registered driver with driverClassName=org.apache.derby.jdbc.EmbeddedDriver was not found, trying direct instantiation. 2020-02-13 08:35:24.311 INFO 15228 --- [ restartedMain] com.zaxxer.hikari.pool.PoolBase : HikariPool-1 - Driver does not support get/set network timeout for connections. (Feature not implemented: No details.) 2020-02-13 08:35:24.313 INFO 15228 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed. 2020-02-13 08:35:24.342 INFO 15228 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default] 2020-02-13 08:35:24.382 INFO 15228 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate Core {5.4.10.Final} 2020-02-13 08:35:24.456 INFO 15228 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final} 2020-02-13 08:35:24.535 INFO 15228 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.DerbyTenSevenDialect 2020-02-13 08:35:24.805 INFO 15228 --- [ restartedMain] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform] 2020-02-13 08:35:24.810 INFO 15228 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default' 2020-02-13 08:35:24.834 INFO 15228 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729 2020-02-13 08:35:24.870 WARN 15228 --- [ restartedMain] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning 2020-02-13 08:35:24.952 INFO 15228 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor' 2020-02-13 08:35:25.035 WARN 15228 --- [ restartedMain] ion$DefaultTemplateResolverConfiguration : Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration) 2020-02-13 08:35:25.197 INFO 15228 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path '' 2020-02-13 08:35:25.198 INFO 15228 --- [ restartedMain] com.example.demo.DemoApplication : Started DemoApplication in 2.991 seconds (JVM running for 3.862) 2020-02-13 08:35:25.238 INFO 15228 --- [ restartedMain] com.example.demo.TableLister : SYSALIASES 2020-02-13 08:35:25.238 INFO 15228 --- [ restartedMain] com.example.demo.TableLister : SYSCHECKS 2020-02-13 08:35:25.239 INFO 15228 --- [ restartedMain] com.example.demo.TableLister : SYSCOLPERMS 2020-02-13 08:35:25.239 INFO 15228 --- [ restartedMain] com.example.demo.TableLister : SYSCOLUMNS 2020-02-13 08:35:25.239 INFO 15228 --- [ restartedMain] com.example.demo.TableLister : SYSCONGLOMERATES 2020-02-13 08:35:25.239 INFO 15228 --- [ restartedMain] com.example.demo.TableLister : SYSCONSTRAINTS 2020-02-13 08:35:25.239 INFO 15228 --- [ restartedMain] com.example.demo.TableLister : SYSDEPENDS 2020-02-13 08:35:25.239 INFO 15228 --- [ restartedMain] com.example.demo.TableLister : SYSFILES 2020-02-13 08:35:25.239 INFO 15228 --- [ restartedMain] com.example.demo.TableLister : SYSFOREIGNKEYS 2020-02-13 08:35:25.239 INFO 15228 --- [ restartedMain] com.example.demo.TableLister : SYSKEYS 2020-02-13 08:35:25.239 INFO 15228 --- [ restartedMain] com.example.demo.TableLister : SYSPERMS 2020-02-13 08:35:25.239 INFO 15228 --- [ restartedMain] com.example.demo.TableLister : SYSROLES 2020-02-13 08:35:25.239 INFO 15228 --- [ restartedMain] com.example.demo.TableLister : SYSROUTINEPERMS 2020-02-13 08:35:25.239 INFO 15228 --- [ restartedMain] com.example.demo.TableLister : SYSSCHEMAS 2020-02-13 08:35:25.239 INFO 15228 --- [ restartedMain] com.example.demo.TableLister : SYSSEQUENCES 2020-02-13 08:35:25.239 INFO 15228 --- [ restartedMain] com.example.demo.TableLister : SYSSTATEMENTS 2020-02-13 08:35:25.239 INFO 15228 --- [ restartedMain] com.example.demo.TableLister : SYSSTATISTICS 2020-02-13 08:35:25.239 INFO 15228 --- [ restartedMain] com.example.demo.TableLister : SYSTABLEPERMS 2020-02-13 08:35:25.239 INFO 15228 --- [ restartedMain] com.example.demo.TableLister : SYSTABLES 2020-02-13 08:35:25.239 INFO 15228 --- [ restartedMain] com.example.demo.TableLister : SYSTRIGGERS 2020-02-13 08:35:25.239 INFO 15228 --- [ restartedMain] com.example.demo.TableLister : SYSUSERS 2020-02-13 08:35:25.239 INFO 15228 --- [ restartedMain] com.example.demo.TableLister : SYSVIEWS 2020-02-13 08:35:25.239 INFO 15228 --- [ restartedMain] com.example.demo.TableLister : SYSDUMMY1 | cs |
반응형
'WEB > 스프링 부트 2' 카테고리의 다른 글
JDBC, Mapper / JPA / TestEntityManagerTest / SessionFactory (0) | 2020.02.14 |
---|---|
MySQL 연결 / 스프링 schema.sql, data.sql / Flyway (0) | 2020.02.13 |
Spring Security Method SpEL (0) | 2020.02.13 |
Spring Security + H2 (0) | 2020.02.12 |
TestRestTemplate, WebTestClient (0) | 2020.02.11 |