์ ์ฒด ๊ธ199 [Spring Boot/RESTful] Spring Security๋ฅผ ์ด์ฉํ ๋ก๊ทธ์ธ [๊ธฐ๋ณธ] dependency ์ถ๊ฐ org.springframework.boot spring-boot-starter-security 1. ์๋์ผ๋ก ์์ฑ๋๋ username, password๋ฅผ ์ด์ฉ 1) ๊ธฐ๋ณธ password ํ์ธ dependency๋ฅผ ์ค์ ํ ํ, ์ดํ๋ฆฌ์ผ์ด์ ์ ์คํํ์ฌ ๋น๋ฐ๋ฒํธ๋ฅผ ํ์ธํด์ผ ํ๋ค. (์น์๋ฒ๋ฅผ ํ์ธํ๊ธฐ ์ํด ํ์) 2) ์น ๋ธ๋ผ์ฐ์ ์์ฒญ ์ธ์ฆ์ด ๋์ด ์์ง ์๋ค๋ฉด 401 Unauthorized๊ฐ ๋ฌ๋ค. ์ฌ๊ธฐ์์ username ๊ฐ์ user๋ก ํด๋ ๋ถ๋ฌ์์ง๋ ์ด์ ๋ spring security์ ๊ธฐ๋ณธ ์ค์ ๋๋ฌธ์ด๋ค. Spring Security ๊ธฐ๋ณธ ์ค์ spring.security.user.name / spring.security.user.password๋ฅผ ์ง์ ํ์ง ์์ผ๋ฉด ๊ธฐ๋ณธ.. 2022. 2. 18. [Spring Boot/RESTful] HAL Browser(Explorer) (+๋ฒ์ ์๋ฌ) HAL Browser Hypertext Application Language REST API ์ค๊ณ ์ Response message์ ํฌ๋งท๊ณผ๋ ์๊ด์์ด API๋ฅผ ์ฝ๊ฒ ์ฌ์ฉํ ์ ์๋ ๋ฉํ์ ๋ณด๋ฅผ ํ์ดํผ๋งํฌ ํ์์ผ๋ก ์ ๊ณตํ๋ค. API ๋ฆฌ์์ค ์ฌ์ด์์ ์ผ๊ด์ ์ธ ํ์ดํผ๋งํฌ๋ฅผ ์ ๊ณต API ์ค๊ณ์์ HAL์ ๋์ ํ๊ฒ ๋๋ฉด API ๊ฐ ์ฌ์ด ๊ฒ์์ด ๊ฐ๋ฅํด์ง๋ค. → ๋ ๋์ ๊ฐ๋ฐํ๊ฒฝ ์ ๊ณต dependency ์ถ๊ฐ org.springframework.data spring-data-rest-hal-browser HAL Browser๊ฐ deprecated ๋์ด์ ์ต์ spring boot ๋ฒ์ ์์๋ HAL explorer๋ฅผ ํตํด ์ฌ์ฉํ๋ฉด ๋๋ค. (์๋์์ ๋ฒ์ ์ถ๊ฐ ์ ํ๋ฉด ์๋ฌ๋จ) org.springframework.dat.. 2022. 2. 18. [Spring Boot/RESTful] REST API Monitoring์ ์ํ Actuator(+spring fox PathPatternParser ์ด์) Actuator ํ์ฌ ๊ธฐ๋ํ๊ณ ์๋ ์ดํ๋ฆฌ์ผ์ด์ ์ ์ํ๋ฅผ ์ฝ๊ฒ monitoringํ ์ ์๋ค. ํ์ฌ ์๋ฒ๊ฐ ๊ตฌ๋ ์ค์ธ์ง๋ ํ์ธ ๊ฐ๋ฅ ๊ธฐ๋ณธ ์ ๊ณตํ๋ ๋งํฌ๋ฅผ ๋ณ๋๋ก ์ปค์คํฐ๋ง์ด์งํด์ ์ฌ์ฉํ๋ฉด ๋ ์ข๋ค. Actuator ๊ตฌํ dependency ์ถ๊ฐ org.springframework.boot spring-boot-starter-actuator ์๋ฌ Actuator๋ PathPatternParser๋ฅผ ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์ ์ง๋ Swagger ์ค์ ์์ ํ์ฉํด์คฌ๋ yml ์ค์ ์ผ๋ก๋ ํด๊ฒฐ๋์ง ์๋๋ค. org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; https://git.. 2022. 2. 18. [Spring Boot/RESTful] Swagger ์ค์ (+๋ฒ์ ์ค๋ฅ) Swagger API ์ค๊ณ, ๋น๋, ๋ฌธ์ํ, ์ฌ์ฉ์ ๋์์ ์ฃผ๋ ์คํ์์ค ํ๋ ์์ํฌ Swagger ๊ตฌํ 1. dependency ์ค์ io.springfox springfox-boot-starter 3.0.0 io.springfox springfox-swagger-ui 3.0.0 ๋ฒ์ ์ค๋ฅ spring boot 2.6 ๋ฒ์ ์ดํ์ spring.mvc.pathmatch.matching-strategy ๊ฐ์ด ant_path_matcher์์ path_pattern_parser๋ก ๋ณ๊ฒฝ๋๋ฉด์ ๋ช๋ช ๋ผ์ด๋ธ๋ฌ๋ฆฌ(swaggerํฌํจ)์ ์ค๋ฅ๊ฐ ๋ฐ์ํ๋ค. Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPo.. 2022. 2. 18. [Spring Boot/RESTful] REST API 3๋จ๊ณ๋ฅผ ์ํ HATEOAS ์ค์ HATEOAS Hypermedia As the Engine Of Application State ํ์ฌ ๋ฆฌ์์ค์ ์ฐ๊ด๋(ํธ์ถ ๊ฐ๋ฅํ) ์์ ์ํ ์ ๋ณด๋ฅผ ์ ๊ณต(mapping) ํด๋ผ์ด์ธํธ๊ฐ ๋ช ์์ ์ผ๋ก ๋งํฌ๋ฅผ ์์ฑํ์ง ์์๋ ์๋ฒ ์ธก์์ ๋ฐ์ ๋งํฌ์ ๋ ํผ๋ฐ์ค๋ฅผ ํตํด ์ดํ๋ฆฌ์ผ์ด์ ์ ์ํ ๋ฐ ์ ์ด๋ฅผ ํํํ ์ ์๋ค. ์ฅ์ - ์์ฒญ URI๊ฐ ๋ณ๊ฒฝ๋๋๋ผ๋ ํด๋ผ์ด์ธํธ์์ ๋์ ์ผ๋ก ์์ฑ๋ URI๋ฅผ ์ฌ์ฉํจ์ผ๋ก์จ, ํด๋ผ์ด์ธํธ๊ฐ URI ์์ ์ ๋ฐ๋ฅธ ์ฝ๋๋ฅผ ๋ณ๊ฒฝํ์ง ์์๋ ๋๋ ํธ๋ฆฌํจ์ ์ ๊ณตํ๋ค. - URI ์ ๋ณด๋ฅผ ํตํด ๋ค์ด์ค๋ ์์ฒญ์ ์์ธกํ ์ ์๊ฒ ๋๋ค. - Resource๊ฐ ํฌํจ๋ URI๋ฅผ ๋ณด์ฌ์ฃผ๊ธฐ ๋๋ฌธ์, Resource์ ๋ํ ํ์ ์ ์ป์ ์ ์๋ค. REST API ์ค๊ณ ๋จ๊ณ 0. The Swamp of POX ํน์ ํ .. 2022. 2. 18. [Spring boot/RESTful] REST API ๋ฒ์ ๊ด๋ฆฌ ๋ฒ์ ๊ด๋ฆฌ ๋จ์ํ๊ฒ ์ฌ์ฉ์์๊ฒ ๋ณด์ฌ์ฃผ๋ ํญ๋ชฉ์ ์ ์ดํ๋ ์ฉ๋๊ฐ ์๋๋ผ REST API์ ์ค๊ณ๊ฐ ๋ณ๊ฒฝ๋๊ฑฐ๋ ์ดํ๋ฆฌ์ผ์ด์ ์ ๊ตฌ์กฐ๊ฐ ๋ฐ๋ ๋๋ ๋ฒ์ ์ ๋ณ๊ฒฝํด์ฃผ์ด์ผ ํ๋ค. ์ฌ์ฉ์์๊ฒ๋ ์ด๋ ํ API ๋ฒ์ ์ ์ฌ์ฉํด์ผ ํ๋์ง ๋ช ์ํด์ผ ํ๋ค. ์ข ๋ฅ 1) URI Versioning : Twitter 2) Request Parameter Versioning : Amazon 3) (Custom) Headers Versioning(MIME) : Microsoft 4) Media type Versioning(content negotiation, accept header) : Github ์ผ๋ฐ ๋ธ๋ผ์ฐ์ ์์ ์คํ ๊ฐ๋ฅ : URI, Request Parameter ์ผ๋ฐ ๋ธ๋ผ์ฐ์ ์์ ์คํ ๋ถ๊ฐ : (Custom) Headers Ve.. 2022. 2. 18. [Spring boot/RESTful] Response Filtering Response ๋ฐ์ดํฐ ์ ์ด๋ฅผ ์ํ Filtering ํด๋ผ์ด์ธํธ์๊ฒ ์ ๋ฌ๋๋ ์ ๋ณด์ ๊ฐ์ ์ ์ด ๋ณดํต 3๊ฐ์ง ๋ฐฉ๋ฒ์ด ์๋ค. ์ค๋์ ์ด ์ค 3๋ฒ์งธ์ ๋ํด ๋ค๋ฃฌ๋ค. ๊ฐ์ ์ํธํํ๊ฑฐ๋ ์นํํ์ฌ ์ ๋ฌ null๋ก ๋ฐํ ์์ ์ ์ธํ๊ณ ๋ฐํ @JsonIgnore Response ๋ฐํ ์ Json๊ฐ์ ํฌํจ๋์ง ์๋๋ก ํ๋ annotation. ๊ฐ๋ณ์ ์ผ๋ก ํ๋ ๊ฐ์ ์ ์ดํ๋ค. @JsonIgnore // ๋ฐํ ์ Json๊ฐ์ ํฌํจ๋์ง ์์ ->๋ฐํ๊ฐ ์ ์ด privateString password; @JsonIgnore privateString ssn; @JsonIgnoreProperties ํด๋น ํด๋์ค ๋ธ๋ก ๋จ์๋ก ํํฐ๋ง @JsonIgnoreProperties(value={"password", "ssn"}) public c.. 2022. 2. 18. [Spring Boot/RESTful] Response ๋ฐ์ดํฐ ํ์ ๋ฐํ(XML format) XML ํ์ผ ํธ์ถ Postman header์์ key: Accept, value: application/xml๋ก ๋ณํ ์ xmlํ์ผ ํธ์ถ ๊ฐ๋ฅ XML ํ์ผ ๋ฐํ ํ์ฉ pom.xml ํ์ผ์ ๊ด๋ จ dependency ์ถ๊ฐ com.fasterxml.jackson.dataformat jackson-dataformat-xml 2.10.2 ⇒ ์ค์ ํ์ง ์์ ๊ฒฝ์ฐ 406 ์๋ฌ๊ฐ ๋๋ค 406 Not Acceptable ์๋ฒ๊ฐ ์์ฒญ์ ์ฌ์ ์ฝํ ์ธ ํ์ ํค๋์ ์ ์ฉ๋ ํ์ฉ ๊ฐ๋ฅํ ๊ฐ ๋ชฉ๋ก๊ณผ ์ผ์นํ๋ ์๋ต์ ์์ฑํ ์ ์์ผ๋ฉฐ ์๋ฒ๊ฐ ๊ธฐ๋ณธ ํํ์ ์ ๊ณตํ ์์ฌ๊ฐ ์์ด์ ๋ฐ์ [์ฌ์ ์ฝํ ์ธ ํ์ ํค๋์ ์ข ๋ฅ] [Accept]() [Accept-Encoding]() [Accept-Language]() ์๋ฒ๋ ๋ณดํต ๊ด๋ จ ํค๋๋ฅผ ๋ฌด.. 2022. 2. 18. [Spring Boot/RESTful] Validation API์ Internationalization Validation API ์ฌ์ฉ์๊ฐ ์ ๋ ฅํ ๋ฐ์ดํฐ์ ๋ํ ์ ํจ์ฑ ์ฒดํฌ -> @Valid annotation ์ฌ์ฉ 1. dependency ์ถ๊ฐ org.hibernate.validator hibernate-validator 6.0.7.Final 2. dto์ ์ ์ฝ์กฐ๊ฑด ์ถ๊ฐ @Data @AllArgsConstructor public class User { private Integer id; @Size(min=2, message = "Name์ 2๊ธ์ ์ด์ ์ ๋ ฅํด์ฃผ์ธ์.") private String name; private String password; @Past // ๊ณผ๊ฑฐ ๋ ์ง๋ง ๊ฐ๋ฅํ ์ ์ฝ ์กฐ๊ฑด private Date joinDate; } 3. controller์ ์ถ๊ฐ JDK์ ํฌํจ๋ API์ hibe.. 2022. 2. 18. ์ด์ 1 ยทยทยท 7 8 9 10 11 12 13 ยทยทยท 23 ๋ค์