#32 multi module: db setting
This commit is contained in:
@@ -1,2 +1,5 @@
|
||||
###
|
||||
GET http://localhost:8080/save
|
||||
GET http://localhost:8080/save
|
||||
|
||||
###
|
||||
GET http://localhost:8080/find
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.example.moduleapi;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
|
||||
@SpringBootApplication(
|
||||
scanBasePackages = {
|
||||
@@ -9,6 +11,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
"com.example.modulecommon"
|
||||
}
|
||||
)
|
||||
@EntityScan("com.example.modulecommon.domain")
|
||||
@EnableJpaRepositories(basePackages = "com.example.modulecommon.repository")
|
||||
public class ModuleApiApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -2,11 +2,15 @@ package com.example.moduleapi.response;
|
||||
|
||||
import com.example.modulecommon.enums.CodeEnum;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class CommonResponse<T> {
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.example.moduleapi.service;
|
||||
|
||||
import com.example.moduleapi.exception.CustomException;
|
||||
import com.example.modulecommon.domain.Member;
|
||||
import com.example.modulecommon.enums.CodeEnum;
|
||||
import com.example.modulecommon.repository.MemberRepository;
|
||||
import com.example.modulecommon.sevice.CommonDemoService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -11,14 +13,22 @@ import org.springframework.stereotype.Service;
|
||||
public class DemoService {
|
||||
|
||||
private final CommonDemoService commonDemoService;
|
||||
private final MemberRepository memberRepository;
|
||||
|
||||
public String save() {
|
||||
memberRepository.save(
|
||||
Member.builder()
|
||||
.name("name")
|
||||
.build()
|
||||
);
|
||||
System.out.println(CodeEnum.SUCCESS.getCode());
|
||||
System.out.println(commonDemoService.commonService());
|
||||
return "save";
|
||||
}
|
||||
|
||||
public String find() {
|
||||
int size = memberRepository.findAll().size();
|
||||
System.out.println("DB size : " + size);
|
||||
return "find";
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1,21 @@
|
||||
spring:
|
||||
main:
|
||||
allow-bean-definition-overriding: true
|
||||
|
||||
datasource:
|
||||
url: jdbc:h2:mem:~/testdb
|
||||
username: sa
|
||||
password:
|
||||
driver-class-name: org.h2.Driver
|
||||
|
||||
jpa:
|
||||
database-platform: org.hibernate.dialect.H2Dialect
|
||||
hibernate:
|
||||
ddl-auto: create
|
||||
properties:
|
||||
hibernate:
|
||||
show_sql: true
|
||||
format_sql: true
|
||||
use_sql_comments: true
|
||||
jdbc:
|
||||
time_zone: Asia/Seoul
|
||||
@@ -2,6 +2,7 @@ plugins {
|
||||
id 'java'
|
||||
id 'org.springframework.boot' version '2.7.8'
|
||||
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
|
||||
id 'java-library'
|
||||
}
|
||||
|
||||
group = 'com.example'
|
||||
@@ -14,6 +15,10 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter'
|
||||
|
||||
api 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||
runtimeOnly 'com.h2database:h2'
|
||||
|
||||
compileOnly 'org.projectlombok:lombok'
|
||||
annotationProcessor 'org.projectlombok:lombok'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.example.modulecommon.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@Entity
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Member {
|
||||
|
||||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.example.modulecommon.repository;
|
||||
|
||||
import com.example.modulecommon.domain.Member;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface MemberRepository extends JpaRepository<Member, Long> {
|
||||
}
|
||||
Reference in New Issue
Block a user