오늘의 코딩순서
(폴더: oBootMSADiscoveryService)
1. eureka 클라우드 서버 만들어 배포
- build.gradle 확인 + OBootMsaDiscoveryServiceApplication + application.yml
(폴더: oBootMSAUserService01 )
2. Micro 서비스 만들기
- build.gradle 확인 + OBootMsaUserService01Application + application.yml
+ Gretting.class + Dept.class + - UserServiceController01
오늘의 코딩 포인트
1. eureka 클라우드 서버 만들어 배포
- build.gradle 확인
plugins {
id 'java'
id 'org.springframework.boot' version '3.3.3'
id 'io.spring.dependency-management' version '1.1.6'
}
group = 'com.oracle'
version = 'version.1.0'
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
repositories {
mavenCentral()
}
ext {
set('springCloudVersion', "2023.0.3")
}
dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
tasks.named('test') {
useJUnitPlatform()
}
- OBootMsaDiscoveryServiceApplication
package com.oracle.oBootMSADiscoveryService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class OBootMsaDiscoveryServiceApplication {
public static void main(String[] args) {
SpringApplication.run(OBootMsaDiscoveryServiceApplication.class, args);
}
}
- application.yml
server:
port: 8761
spring:
application:
name: service-discovery
eureka:
client:
register-with-eureka: false
# 클라이언트가 eureka 서비스에 자신을 등록하지 않음
fetch-registry: false
# 레지스트리 정보를 클라이언트 로컬에 캐싱하지 않음
# eureka 클라이언트가 eureka 서비스에 등록시 설정 가능
service-url:
defaultZone: http://localhost:8761/eureka/
2. Micro 서비스 만들기
- build.gradle 확인
plugins {
id 'java'
id 'org.springframework.boot' version '3.3.3'
id 'io.spring.dependency-management' version '1.1.6'
}
group = 'com.oracle'
version = 'version.1.0'
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
ext {
set('springCloudVersion', "2023.0.3")
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
tasks.named('test') {
useJUnitPlatform()
}
- OBootMsaUserService01Application
package com.oracle.oBootMSAUserService01;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@SpringBootApplication
@EnableDiscoveryClient
public class OBootMsaUserService01Application {
public static void main(String[] args) {
SpringApplication.run(OBootMsaUserService01Application.class, args);
}
}
- application.yml
server:
port: 0
spring:
application:
name: user-service01
eureka:
instance:
instance-id: ${spring.application.name}:${spring.application.instance_id:${random.value}}
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultzone: http://127.0.0.1:8761/eureka/
greeting:
message: welcome to MSA
- Greeting.class
package com.oracle.oBootMSAUserService01.vo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import lombok.Data;
@Component
@Data
public class Greeting {
@Value("${greeting.message}")
private String message;
}
- Dept.class
package com.oracle.oBootMSAUserService01.vo;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@ToString
public class Dept {
private int deptno;
private String dname;
private String loc;
}
- UserServiceController01
package com.oracle.oBootMSAUserService01.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.oracle.oBootMSAUserService01.vo.Greeting;
@RestController
@RequestMapping("/")
public class UserServiceController01 {
private Environment env;
@Autowired
public UserServiceController01(Environment env) {
this.env = env;
}
@Autowired
public Greeting greeting;
@GetMapping("/health_check")
public String health_check() {
System.out.println("health_check Start...");
return "health_check On";
}
}
- UserServiceController01
package com.oracle.oBootMSAUserService01.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.oracle.oBootMSAUserService01.vo.Dept;
import com.oracle.oBootMSAUserService01.vo.Greeting;
@RestController
@RequestMapping("/")
public class UserServiceController01 {
private Environment env;
@Autowired
public UserServiceController01(Environment env) {
this.env = env;
}
@Autowired
public Greeting greeting;
@GetMapping("/health_check")
public String health_check() {
System.out.println("health_check Start...");
return "health_check On";
}
@GetMapping("/greetingMessage")
public String greetingMessage() {
System.out.println("greetingMessage Start...");
return greeting.getMessage();
}
@GetMapping("/deptMessage")
public Dept deptMessage(Dept dept) {
System.out.println("greetingMessage Start...");
dept.setDeptno(1234);
dept.setDname(greeting.getMessage());
dept.setLoc("홍대");
return dept;
}
}
질문목록
수업교재
오늘의 숙제
'Cloud&etc' 카테고리의 다른 글
2024_09_09_월_클라우드 시험(클라우드 플랫폼 기반 서비스 운영 실습) (0) | 2024.09.09 |
---|---|
2024_08_23_금 (0) | 2024.08.23 |
2024_08_22_목~08_23_금 (0) | 2024.08.22 |