백기선 (40) 썸네일형 리스트형 [Spring Boot] Actuator (Spring-Boot-Admin) 1. Spring-Boot-Admin spring에서 제공하는 것이 아니라 제 3자가 오픈 소스로 제공하는 application 설정한 actuator 정보를 UI로 확인 가능 어드민 서버 필요 2. 어드민 서버 설정 ! spring-security 적용 필요 de.codecentric:spring-boot-admin-starter-server 의존성 추가 application에 @EnableAdminServer 어노테이션 추가 de.codecentric spring-boot-admin-starter-server 2.6.6 @SpringBootApplication @EnableAdminServer public class Application { public static void main(String[] .. [Spring Boot] Actuator (HTTP/JMX) 1. Spring Actuator 운영 중인 애플리케이션을 HTTP나 JMX를 이용해서 모니터링하고 관리할 수 있는 기능 org.springframework.boot:spring-boot-starter-actuator 의존성 추가 2. 애플리케이션의 각종 정보를 확인할 수 있는 Endpoints 다양한 Endpoints 제공 JMX 또는 HTTP를 통해 접근 가능 함 활성화 및 노출여부 설정 가능 shutdown을 제외한 모든 Endpoint는 기본적으로 활성화 상태 Web은 health만 노출여부 활성화 상태 (JMX는 거의 대부분이 활성화 상태) 활성화 옵션 조정 management.endpoints.enabled-by-default=false management.endpoint.info.enable.. [Spring Boot] REST Client 커스터마이징 1. WebClient : 기본으로 Reactor Netty의 HTTP 클라이언트 사용 ① 로컬 커스터마이징 WebClient webClient = builder.baseUrl("http://localhost:8080").build(); Mono helloMono = webClient.get().uri("/hello") .retrieve().bodyToMono(String.class); ② 글로벌 커스터마이징 - WebClientCustomizer //@Bean //public WebClientCustomizer webClientCustomizer() { // return new WebClientCustomizer() { // @Override // public void customize(WebClien.. [Spring Boot] REST Client (RestTemplate과 WebClient) 1. REST Client Spring Framework에서 제공 Spring Boot는 REST Client를 쉽게 사용할 수 있도록 빈을 등록해줌 RestTemplate, WebClient 타입의 빈을 등록해주는 것이 아니라 RestTemplateBuilder, WebClient.Builder를 빈으로 등록해줌 2. RestTemplate Blocking I/O 기반의 Synchronous API 실행 중인 라인이 끝나기 전까지 다음 라인으로 넘어가지 않음 (순차적 처리) RestTemplateAutoConfiguration 프로젝트에 spring-web 모듈이 있다면 RestTemplateBuilder를 빈으로 등록해줌 https://docs.spring.io/spring/docs/current/s.. [Spring Boot] Spring Security 설정 커스터마이징 1. 웹 시큐리티 설정 아래와 같은 화면에서 My에만 인증이 필요하게 변경하고 싶은 경우 WebSecurityConfigurerAdapter를 상속받는 Config 파일 생성 -> 이렇게 되면 Spring Boot가 제공하는 Security 자동설정은 적용되지 않음 @Configuration public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/", "/hello").permitAll() .anyRequest().authenticated().. [Spring Boot] Spring Security 1. 스프링 시큐리티 웹 시큐리티 메소드 시큐리티 다양한 인증 방법 지원 - LDAP, 폼 인증, Basic 인증, OAuth, ... - 기본적으로 Basic 인증 (Accept 헤더에 TEXT_HTML로 지정할 경우 폼 인증) 2. 스프링 부트 시큐리티 자동 설정 SecurityAutoConfiguration : Spring Security가 들어있는 경우에 자동으로 적용되는 설정 파일 UserDetailsServiceAutoConfiguration : Spring Boot application이 뜰 때, 기본 사용자 생성 spring-boot-starter-security 모든 요청에 인증 필요 인증 관련 각종 이벤트 발생 - DefaultAuthenticationEventPublisher 빈 등록.. [Spring Boot] Neo4j 1. Neo4j 노드간의 연관 관계를 영속화하는데 유리한 그래프 데이터베이스 2. 의존성 추가 org.springframework.boot spring-boot-starter-data-neo4j 3. Neo4j 설치 및 실행 (도커) ① Neo4j 설치 docker run -p 7474:7474 -p 7687:7687 -d --name neo4j_boot neo4j - 7474 : http 용 - 7687 : Bolt 프로토콜 용 ② Neo4j Browser http://localhost:7474/browser 기본 패스워드 : neo4j 패스워드 변경 시 appliation.properties 변경 필요 - spring.neo4j.authentication.username=neo4j - spring.n.. [Spring Boot] Mongo DB 1. MongoDB JSON 기반의 도큐먼트 데이터베이스 스키마가 없음 Redis와 비슷하게 콘솔에 접근해서 확인 가능 2. 의존성 추가 org.springframework.boot spring-boot-starter-data-mongodb 3. MongoDB 설치 및 실행 (도커) ① MongoDB 설치 docker run -p 27017:27017 --name mongo_boot -d mongo ② 실행 docker exec -i -t mongo_boot bash mongo 4. 스프링 데이터 몽고DB ① collection : table이름 정도라고 보면 됨 @Document(collection = "accounts") public class Account { @Id private String id.. [Spring Boot] Redis 1. Redis 캐시, 메시지 브로커, 키/밸류 스토어 등으로 사용 가능 2. 의존성 추가 org.springframework.boot spring-boot-starter-data-redis 3. Redis 설치 및 실행 (도커) ① Redis 설치 docker run -p 6379:6379 --name redis_boot -d redis ② 실행 docker exec -i -t redis_boot redis-cli 4. 스프링 데이터 Redis https://projects.spring.io/spring-data-redis/ StringRedisTemplate 또는 RedisTemplate extends CrudRepository # RedisRunner @Component public class Re.. [Spring Boot] 데이터베이스 마이그레이션 - Flyway 1. 의존성 추가 org.flywaydb flyway-core 2. 마이그레이션 디렉토리 db/migration 또는 db/migration/{vendor} (특정 벤더마다 만들 수도 있음) spring.flyway.locations로 변경 가능 ex) resources/db/migration 3. 마이그레이션 파일 이름 V숫자__이름.sql V는 꼭 대문자로 숫자는 순차적으로 (타임스탬프 권장) 숫자와 이름 사이에 언더바 두 개 이름은 가능한 서술적으로 ex) V1__init.sql # 마이그레이션 디렉토리 안에 마이그레이션 파일이 없는 경우 # 파일 이름이 소문자로 시작하는 경우 # 정상적으로 실행 시 -- V1__init.sql drop table if exists account; drop sequ.. 이전 1 2 3 4 다음