본문 바로가기

전자정부프레임워크

표준프레임워크) MSA_적용 개발 실습 -2

Customers 서비스 프로젝트 생성

 

next

 

 

 

finish

 

 

 

파일 구성

 

 

 

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.7.4</version>
		<relativePath /> <!-- lookup parent from repository -->
	</parent>
	<groupId>egovframework.msa.sample</groupId>
	<artifactId>Customers</artifactId>
	<version>1.0.0</version>
	<name>Customers</name>
	<description>MSA Sample Project</description>
	<properties>
		<java.version>1.8</java.version>
		<org.egovframe.rte.version>4.0.0</org.egovframe.rte.version>
		<spring.cloud.version>2.2.5.RELEASE</spring.cloud.version>
	</properties>
	<repositories>
		<repository>
			<id>mvn2s</id>
			<url>https://repo1.maven.org/maven2/</url>
			<releases>
				<enabled>true</enabled>
			</releases>
			<snapshots>
				<enabled>true</enabled>
			</snapshots>
		</repository>
		<repository>
			<id>egovframe</id>
			<url>http://maven.egovframe.go.kr/maven/</url>
			<releases>
				<enabled>true</enabled>
			</releases>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</repository>
	</repositories>
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter</artifactId>
			<exclusions>
				<exclusion>
					<groupId>org.springframework.boot</groupId>
					<artifactId>spring-boot-starter-logging</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
			<exclusions>
				<exclusion>
					<groupId>org.junit.vintage</groupId>
					<artifactId>junit-vintage-engine</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<!-- 표준프레임워크 실행환경 -->
		<dependency>
			<groupId>org.egovframe.rte</groupId>
			<artifactId>org.egovframe.rte.fdl.cmmn</artifactId>
			<version>${org.egovframe.rte.version}</version>
		</dependency>
		<dependency>
			<groupId>org.egovframe.rte</groupId>
			<artifactId>org.egovframe.rte.ptl.mvc</artifactId>
			<version>${org.egovframe.rte.version}</version>
		</dependency>
	
	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>
</project>

 

 

 

application.yml 파일 소스 내용

properties -> yml 변경

server:
port: 8082
spring:
application:
name: customer

앞에선 포트번호 5081, 5082 사용으로 적었는데 편하신 걸로 사용 하시면 됩니다.

예제는 8082로 적음

 

CustomersApplication.java 파일 작성

package egovframework.msa.sample;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@ComponentScan("egovframework.*")
@SpringBootApplication
public class CustomersApplication {
public static void main(String[] args) {
SpringApplication.run(CustomersApplication.class, args);
}
}

 

CustomerController.java 파일 작성

package egovframework.msa.sample.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/customers")
public class CustomerController {
@GetMapping("/{customerId}")
public String getCustomerDetail(@PathVariable String customerId) {
System.out.println("request customerId :" + customerId);
return "[Customer id = " + customerId + " at " + System.currentTimeMillis() + "]";
}
}

 

 

URL : http://localhost:8082/customers/1234