본문 바로가기

전체 글

(124)
[Spring] API 1. API 템플릿 엔진과의 차이는 뷰없이 데이터가 그대로 요청한 클라이언트에 전달됨 @ResponseBody를 사용하면 viewResolver를 사용하지 않음 HTTP의 Body에 문자 내용을 직접 반환(HTML BODY TAG 아님) @ResponseBody를 사용하고 객체를 반환하는 경우 Spring에서는 기본적으로 JSON으로 변환됨 ① 문자 반환 @GetMapping("hello-string") @ResponseBody public String helloString(@RequestParam("name") String name) { return "hello " + name; } http://localhost:8080/hello-string?name=spring 로 접근 시 : "hello spri..
[Spring] MVC와 템플릿 엔진 1. MVC Model, View, Controller 과거에는 Controller, View가 분리되어 있지 않았음 View에서 모든 것을 처리 (ex. jsp) -> Model1 방식 View : 화면에 관련된 일만 / Controller : 비즈니스 로직, 뒷 단에 관련된 일 2. 템플릿 엔진 템플릿 엔진 : html을 서버에서의 처리를 통해 동적으로 바꿔서 전달 ex) jsp, php thymeleaf 템플릿 엔진 장점 : 서버없이 열어봐도 구조를 볼 수 있음 hello! empty {name} : Mode에 key가 name인 것의 값을 가져와서 치환해줌 ① 서버없이 절대경로로 접근 시 : hello! empty 확인 가능 (서버없이 구조 확인 가능) ② Controller에 "hello-mvc..
[Spring] 정적 컨텐츠 1. Spring 웹 개발 방식 ① 정적 컨텐츠 - 서버에서의 처리없이 파일을 그대로 웹 브라우저에 전달 ② MVC와 템플릿 엔진 - MVC : Model, View, Controller - 템플릿 엔진 : html을 서버에서의 처리를 통해 동적으로 바꿔서 전달 ex) jsp, php ③ API - JSON 데이터 포맷으로 클라이언트에 전달 - 서버끼리 통신할 때도 사용 2. 정적 컨텐츠 Spring Boot는 기본적으로 정적 컨텐츠 기능을 제공 /static, /public, /resources, /META-INF/resources 에 위치한 파일을 찾아 웹 브라우저에 그대로 전달 ① 웹 브라우저에서 localhost:8080/hello-static.html 요청 ② 내장 톰캣 서버가 요청을 받아서 S..
[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..