#13 spring db: test - embedded db

This commit is contained in:
haerong22
2022-06-28 01:40:02 +09:00
parent 03720662be
commit aa20fd5559
3 changed files with 27 additions and 2 deletions

View File

@@ -2,13 +2,17 @@ package hello.itemservice;
import hello.itemservice.config.*;
import hello.itemservice.repository.ItemRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Profile;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import javax.sql.DataSource;
@Slf4j
//@Import(MemoryConfig.class)
//@Import(JdbcTemplateV1Config.class)
//@Import(JdbcTemplateV2Config.class)
@@ -26,4 +30,16 @@ public class ItemServiceApplication {
return new TestDataInit(itemRepository);
}
// 임베디드 DB
// @Bean
// @Profile("test")
// public DataSource dataSource() {
// log.info("메모리 데이터베이스 초기화");
// DriverManagerDataSource dataSource = new DriverManagerDataSource();
// dataSource.setDriverClassName("org.h2.Driver");
// dataSource.setUrl("jdbc:h2:mem:db;DB_CLOSE_DELAY=-1");
// dataSource.setUsername("sa");
// dataSource.setPassword("");
// return dataSource;
// }
}

View File

@@ -1,7 +1,7 @@
spring.profiles.active=test
spring.datasource.url=jdbc:h2:tcp://localhost/~/testcase
spring.datasource.username=sa
#spring.datasource.url=jdbc:h2:tcp://localhost/~/testcase
#spring.datasource.username=sa
#jdbcTemplate sql log
logging.level.org.springframework.jdbc=debug

View File

@@ -0,0 +1,9 @@
drop table if exists item CASCADE;
create table item
(
id bigint generated by default as identity,
item_name varchar(10),
price integer,
quantity integer,
primary key (id)
);