모노리식 → MSA 전환
대형 서비스에 적합하지만, 현재 프로젝트가 그런 서비스라고 가정!하고 전환을 시작.
각 비지니스 로직을 분리해 개별 프로젝트로 생성.
제일 앞단에 API Gateway (분배기) 통해 서버 요청 분산 관리할 수 있다.
이러한 이유들로 대형 서비스들 MSA로 전환. but, 단점도 존재.



config repository를 깃허브에 private으로 만들었으므로 config server 접속 위해서 비대칭 키 사용.
public키는 깃허브 리포지토리에 저장해두고 config repository에서 private키 통해 접속.
쉘에서 ssh-keygen 명령어 통해 비대칭키 생성 (git bash를 사용했다)
ssh-keygen -m PEM -t rsa -b 4096 -C "코멘트"
파일 위치
C:\Users\blues\.ssh
public키 내용 복사해서 깃허브 리포지토리에 등록.
settings - deploy keys


@Configuration
@EnableWebSecurity
public class SecurityConfig {
// 인코딩
@Bean
public BCryptPasswordEncoder bCryptPasswordEncoder() {
return new BCryptPasswordEncoder();
}
// 시큐리티 필터
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.csrf((auth) -> auth.disable());
// 모든 경로에 대해 특정 권한 필요
http.authorizeHttpRequests((auth) -> auth.anyRequest().authenticated());
// httpBasic 통한 로그인
http.httpBasic(Customizer.withDefaults());
return http.build();
}
// 이 내부에 접근할 수 있는 id, pw
// 한두개이기 때문에 인메모리로 저장
@Bean
public UserDetailsService userDetailsService() {
UserDetails user1 = User.builder()
.username("admin")
.password(bCryptPasswordEncoder().encode("1234"))
.roles("ADMIN")
.build();
return new InMemoryUserDetailsManager(user1);
}
}
httpBasic 형식으로 로그인 진행

로그인 후 config repository에 저장되어 있는 데이터 가져오려면 특정 경로로 접근해야 함.

저장된 설정 정보 가져온 모습.
config server는 config client가 요청하면 데이터를 전해줌.
스프링부트 어플리케이션에 config client 설정 진행.

plugins {
id 'java'
id 'org.springframework.boot' version '3.2.3'
id 'io.spring.dependency-management' version '1.1.4'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
java {
sourceCompatibility = '17'
}
repositories {
mavenCentral()
}
ext {
set('springCloudVersion', "2023.0.0")
}
dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-config'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
tasks.named('test') {
useJUnitPlatform()
}
application.properties
spring.application.name=이름
spring.profiles.active=환경
spring.config.import=optional:configserver:http://아이디:비밀번호@아이피:포트
spring.application.name=ms1
spring.profiles.active=dev
spring.config.import=optional:configserver:http://admin:1234@localhost:9000
config repository에 여러개의 설정 파일 만들어두고, 각 클라이언트마다 필요한 설정 가져다 쓸 수 있음.
<참고>
https://www.youtube.com/playlist?list=PLJkjrxxiBSFBPk-6huuqcjiOal1KdU88R