Open snaag opened 1 year ago
https://ko.wikipedia.org/wiki/H2_(DBMS)
cd h2/bin
chmod 755 h2.sh
./h2.sh
create table member
(
id bigint generated by default as identity not null,
name varchar(255),
primary key(id)
)
insert into member (name) values ('name1');
implementation 'org.springframework.boot:spring-boot-starter-jdbc' // jdbc 드라이버
runtimeOnly 'com.h2database:h2' // db client
spring.datasource.url=jdbc:h2:tcp://localhost/~/test
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.username=sa
@Configuration
public class SpringConfig {
// +++++++++++++++
private DataSource dataSource;
@Autowired
public SpringConfig(DataSource dataSource) {
this.dataSource = dataSource;
}
// +++++++++++++++
// spring bean 에 등록하라는 뜻
@Bean
public MemberService memberService() {
return new MemberService(memberRepository());
}
@Bean
public MemberRepository memberRepository() {
// 주석 처리함
// return new MemoryMemberRepository();
return new JdbcMemberRepository(dataSource);
}
}