반응형
우연히 면접자의 과제를 체크하기전에 따로 디비설치하기 싫어서 h2데이터베이스로 셋팅해서 코드랑 디비보기위해서 셋팅
resources -> application.properties
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console
spring.datasource.hikari.driver-class-name=org.h2.Driver
spring.datasource.hikari.jdbc-url=jdbc:h2:mem:testdb
spring.datasource.hikari.username=sa
spring.datasource.hikari.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=create-drop
H2ServerConfiguration.java
import com.zaxxer.hikari.HikariDataSource;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.h2.tools.Server;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class H2ServerConfiguration {
@Bean
@ConfigurationProperties("spring.datasource.hikari")
public DataSource dataSource() throws SQLException {
Server.createTcpServer("-tcp", "-tcpAllowOthers", "-tcpPort", "8089").start();
return new HikariDataSource();
}
}
반응형
댓글