๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๊ฐœ๋ฐœ/Spring8

Spring boot with Swagger 3.0 OpenAPI๋ž€? OpenAPI Specification(OAS)๋ผ๊ณ ๋„ ํ•˜๋Š” OpenAPI๋Š” RESTful API๋ฅผ ๊ธฐ์ •์˜๋œ ๊ทœ์น™์— ๋งž๊ฒŒ API Spec์„ json์ด๋‚˜ yaml๋กœ ํ‘œํ˜„ํ•˜๋Š” ๋ฐฉ์‹์„ ์˜๋ฏธํ•œ๋‹ค. RESTful API ๋ฅผ ๊ธฐ์ˆ ํ•˜๋Š” ํ‘œ์ค€์œผ๋กœ ์„œ๋น„์Šค์—์„œ ์ œ๊ณตํ•˜๋Š” API ์˜ ๊ธฐ๋Šฅ๊ณผ End Point ๋ฅผ ๊ฐœ๋ฐœ์ž๋‚˜ ์‹œ์Šคํ…œ์ด ์ž๋™์œผ๋กœ ๋ฐœ๊ฒฌํ•˜๊ณ  ์ฒ˜๋ฆฌํ•˜๋Š”๋ฐ ํ•„์š”ํ•œ ์ •๋ณด๋ฅผ ์ œ๊ณตํ•œ๋‹ค. ์ „์—๋Š” Swagger 2.0๊ณผ ๊ฐ™์€ ์ด๋ฆ„์œผ๋กœ ๋ถˆ๋ ธ๋‹ค๊ฐ€ 3.0๋ฒ„์ „์œผ๋กœ ์˜ฌ๋ผ์˜ค๋ฉด์„œ OpenAPI 3.0 Specification(๋˜๋Š” Swagger 3.0)์œผ๋กœ ์นญํ•œ๋‹ค. ๐Ÿ”Ž Open API(Open Application Programming Interface, ๊ณต๊ฐœ API) ๋ˆ„๊ตฌ๋‚˜ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ๊ณต๊ฐœ๋œ API๋ฅผ ๋งํ•œ๋‹ค. Public.. 2022. 11. 3.
Spring Security ์ค‘๋ณต ๋กœ๊ทธ์ธ ๋ฐฉ์ง€ ์„ค์ • WebSecurityConfigurerAdapter๋ฅผ ๊ตฌํ˜„ํ•œ Spring Security ์„ค์ • ํŒŒ์ผ ๋‚ด ์•„๋ž˜์™€ ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค. http .sessionManagement() .maximumSessions(1) .maxSessionsPreventsLogin(false) .expiredUrl("/login") .sessionRegistry(sessionRegistry()); - maximumSessions ์ตœ๋Œ€ ์œ ์ง€ ๊ฐ€๋Šฅํ•œ ์„ธ์…˜ ์ˆ˜๋Š” 1๋กœ ์„ค์ • - maxSessionsPreventsLogin ์€ ์ค‘๋ณต ๋กœ๊ทธ์ธ์ด ๋˜์—ˆ์„ ๋•Œ ๋จผ์ € ๋กœ๊ทธ์ธํ•œ ์‚ฌ์šฉ์ž๋ฅผ ์„ธ์…˜ ์•„์›ƒ ์‹œํ‚ค๋ ค๋ฉด false, ๋‚˜์ค‘์— ๋กœ๊ทธ์ธํ•œ ์‚ฌ์šฉ์ž๋ฅผ ํŠ•๊ธฐ๋ ค๋ฉด true๋กœ ์„ค์ • @Configuration @EnableWebSecurity @Required.. 2022. 3. 15.
Spring Boot ํ”„๋กœ์ ํŠธ git ์—ฐ๋™ Spring Boot + Git Spring Boot ํ”„๋กœ์ ํŠธ ํ˜•์ƒ ๊ด€๋ฆฌ๋ฅผ ์œ„ํ•ด git๊ณผ ์—ฐ๋™ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค. 1. Clone Git Repository STS์—์„œ Window > Show View > Other... > Git ๊ฒ€์ƒ‰ > Git Repositories ์„ ํƒ ์˜ค๋ฅธ ์ชฝ ์ƒ๋‹จ์— Open Perspective ๋ฒ„ํŠผ(ํ…Œ์ด๋ธ” + ๋ฒ„ํŠผ)์„ ๋ˆŒ๋Ÿฌ ๋” ์‰ฝ๊ฒŒ Git Repository์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋‹ค. 2. Clone Git Repository Clone a Git repository ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ ์ž์‹ ์˜ git respository์—์„œ ๋ณต์‚ฌํ•œ url๊ณผ git ID/PW๋ฅผ ๋„ฃ์–ด์ค€๋‹ค. ๋‹ค์Œ์œผ๋กœ ๋„˜์–ด๊ฐ€ ๋กœ์ปฌ ์ €์žฅ์†Œ๋ฅผ ์ง€์ •ํ•œ๋‹ค. ์ด๋ ‡๊ฒŒ ๋งŒ๋“ค๋ฉด Git Repository์— ๋‚ด๊ฐ€ ์—ฐ๊ฒฐํ•œ repository๊ฐ€ ์ถ”๊ฐ€๋œ๋‹ค.. 2022. 3. 9.
Spring Boot์— MySQL / Mybatis ์—ฐ๊ฒฐํ•˜๊ธฐ Spring Boot + MyBatis + MySQL Spring Boot ํ”„๋กœ์ ํŠธ์—์„œ MyBatis๋ฅผ ์ด์šฉํ•œ MySQL ์—ฐ๋™ ๋ฐฉ๋ฒ•์ด๋‹ค. * Spring Boot ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ๊ธฐ๋ณธ์ ์ธ ์„ธํŒ…์„ ํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์—ฌ๊ธฐ์— 1. ์˜์กด์„ฑ ์ถ”๊ฐ€ mybatis ๋ฐ mysql์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ํ•ด๋‹น ์˜์กด์„ฑ์„ ์ถ”๊ฐ€ํ•œ๋‹ค. maven์„ ์‚ฌ์šฉํ•˜๋Š” ํ”„๋กœ์ ํŠธ์˜ ์„ค์ •ํŒŒ์ผ์ธ pom.xml์—์„œ ์˜์กด์„ฑ์„ ์ถ”๊ฐ€ํ•˜๋ฉด ๊ธ€๋กœ๋ฒŒ ์ €์žฅ์†Œ์—์„œ ํ•„์š”ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๋กœ์ปฌ ์ €์žฅ์†Œ๋กœ ๋‹ค์šด๋กœ๋“œํ•˜๊ณ  ํด๋ž˜์Šค ํŒจ์Šค๋ฅผ ์ง€์ •ํ•˜์—ฌ ํ”„๋กœ์ ํŠธ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•œ๋‹ค. ์•„๋ž˜ ๋งํฌ์˜ MVN Repository์—์„œ ์›ํ•˜๋Š” ์˜์กด์„ฑ์„ ๊ฒ€์ƒ‰ํ•˜์—ฌ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๋‹ค. ๋ณดํ†ต ๋ณดํŽธ์ ์ธ ๋ฒ„์ „์ด๋‚˜ ์ตœ์‹  ๋ฒ„์ „์„ ์‚ฌ์šฉํ•œ๋‹ค. https://mvnrepository.com/artifact/mysq.. 2022. 3. 9.
Spring Boot ํ”„๋กœ์ ํŠธ ์ƒ์„ฑํ•˜๊ธฐ Spring Boot ํ”„๋กœ์ ํŠธ ์ƒ์„ฑํ•˜๊ธฐ STS์—์„œ Spring Boot ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค. 1. File > New > Spring Starter Project > Spring Starter Project ์„ ํƒ Spring Starter Project: Spring Boot๋ฅผ ์ด์šฉํ•˜๋Š” ํ”„๋กœ์ ํŠธ Spring Legacy Project: ์ผ๋ฐ˜์ ์ธ Spring Framework ํ”„๋กœ์ ํŠธ * Spring Starter Project๊ฐ€ ๋ณด์ด์ง€ ์•Š์„ ๊ฒฝ์šฐ ๋งจ ์•„๋ž˜ Other... ์—์„œ ๊ฒ€์ƒ‰ 2. New Spring Starter Project ์„ค์ • ํ”„๋กœ์ ํŠธ ๊ธฐ๋ณธ ์„ค์ • 3. New Spring Starter Project Dependencies ์„ค์ • ์Šคํ”„๋ง ๋ถ€ํŠธ์—์„œ ํŠน์ • ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•œ ๋ผ์ด๋ธŒ.. 2022. 3. 8.
JPA, Hibernate ORM (Object Relational Mapping) ๊ฐ์ฒด์™€ ๊ด€๊ณ„ํ˜• ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ ํ…Œ์ด๋ธ”์„ ๋งคํ•‘ํ•œ๋‹ค๋Š” ์˜๋ฏธ์ด๋‹ค. ๊ฐ์ฒด๋Š” ๊ฐ์ฒด๋Œ€๋กœ, ๊ด€๊ณ„ํ˜• DB๋Š” ๊ด€๊ณ„ํ˜• DB๋Œ€๋กœ ์„ค๊ณ„ ORM ํ”„๋ ˆ์ž„์›Œํฌ๊ฐ€ ์ค‘๊ฐ„์—์„œ ๋งคํ•‘(์—ฐ๊ฒฐ) ๊ฐ์ฒด๋ฅผ ๊ด€๊ณ„ํ˜• DB ํ…Œ์ด๋ธ”์— ์ž๋™์œผ๋กœ ์˜์†ํ™” JPA (Java Persistence API) ์ž๋ฐ” ORM์— ๋Œ€ํ•œ API ํ‘œ์ค€ ๋ช…์„ธ๋ฅผ ์˜๋ฏธํ•œ๋‹ค. JPA๋Š” ORM์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ ์ธํ„ฐํŽ˜์ด์Šค์˜ ๋ชจ์Œ์œผ๋กœ JPA๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์ด๋ฅผ ๊ตฌํ˜„ํ•œ Hibernate, DataNucleus, EclipseLink ๋“ฑ๊ณผ ๊ฐ™์€ ORM ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค. JPA๋Š” ๋‚ด๋ถ€์ ์œผ๋กœ JDBC API๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ SQL์„ ์ƒ์„ฑํ•˜๊ณ  ํ˜ธ์ถœํ•œ๋‹ค. ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜๊ณผ JDBC ์‚ฌ์ด์—์„œ ๋™์ž‘ํ•˜์—ฌ ๊ฐœ๋ฐœ์ž๊ฐ€ ์ง์ ‘ JDBC API๋ฅผ ์“ฐ์ง€ .. 2022. 3. 8.
Spring Security Spring Security๋ž€? Spring ๊ธฐ๋ฐ˜์˜ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ๋ณด์•ˆ(์ธ์ฆ๊ณผ ๊ถŒํ•œ, ์ธ๊ฐ€ ๋“ฑ)์„ ๋‹ด๋‹นํ•˜๋Š” ์Šคํ”„๋ง ํ•˜์œ„ ํ”„๋ ˆ์ž„์›Œํฌ์ด๋‹ค. ์ฃผ๋กœ ์„œ๋ธ”๋ฆฟ ํ•„ํ„ฐ์™€ ์ด๋“ค๋กœ ๊ตฌ์„ฑ๋œ ํ•„ํ„ฐ ์ฒด์ธ์œผ๋กœ ๋˜์–ด์žˆ๋‹ค. ์‚ฌ์šฉ์ž์˜ ์š”์ฒญ์„ ๊ฐ€๋กœ์ฑ„๊ณ  Spring Security ํ”„๋กœ์„ธ์Šค์— ๋ณด์•ˆ ์ฒ˜๋ฆฌ๋ฅผ ์œ„์ž„ํ•˜๋Š” ์ผ๋ จ์˜ ๊ณผ์ •์„ ์˜๋ฏธํ•œ๋‹ค. ์ธ์ฆ ์ ˆ์ฐจ๋ฅผ ๊ฑฐ์นœ ํ›„ ์ธ๊ฐ€ ์ ˆ์ฐจ๋ฅผ ์ง„ํ–‰ํ•˜๋ฉฐ ์•„์ด๋””(Principal), ๋น„๋ฐ€๋ฒˆํ˜ธ(Credential)๋ฅผ ์‚ฌ์šฉํ•˜๋Š” Credential ๊ธฐ๋ฐ˜์˜ ์ธ์ฆ ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•œ๋‹ค. ๊ธฐ๋ณธ์ ์œผ๋กœ ์ธ์ฆ ์ •๋ณด๋Š” ์ธ๋ฉ”๋ชจ๋ฆฌ ์„ธ์…˜ ์ €์žฅ์†Œ์ธ SecurityContextHolder์— ์„ธ์…˜-์ฟ ํ‚ค ๋ฐฉ์‹์œผ๋กœ ์ €์žฅ๋œ๋‹ค. Security 3.2 ๋ฒ„์ „๋ถ€ํ„ฐ๋Š” xml๋กœ ์„ค์ •ํ•˜์ง€ ์•Š๊ณ  ์ž๋ฐ” bean์œผ๋กœ ๊ฐ„๋‹จํ•˜๊ฒŒ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋„๋ก ์ง€์›ํ•œ๋‹ค. ๐Ÿ”Ž ์ธ์ฆ(Au.. 2022. 3. 7.
WAS ๋™์ž‘๊ณผ์ • / ์„œ๋ธ”๋ฆฟ(Servlet) / Servlet ๊ตฌํ˜„ / ์„œ๋ธ”๋ฆฟ ์ปจํ…Œ์ด๋„ˆ ๋ชฉ์ฐจ WAS ๋™์ž‘ ๊ณผ์ • ์„œ๋ธ”๋ฆฟ(Servlet) Servlet ๊ตฌํ˜„ ๋ฐฉ๋ฒ• ์„œ๋ธ”๋ฆฟ ์ƒ๋ช…์ฃผ๊ธฐ(Servlet LifeCycle) ์„œ๋ธ”๋ฆฟ ์ปจํ…Œ์ด๋„ˆ(Servlet Container) WAS ๋™์ž‘ ๊ณผ์ • ์›น ์„œ๋ฒ„๋กœ๋ถ€ํ„ฐ ์š”์ฒญ์ด ๋“ค์–ด์˜ค๋ฉด ์ปจํ…Œ์ด๋„ˆ๊ฐ€ web.xml์„ ์ฐธ์กฐํ•˜์—ฌ Servlet์— ๋Œ€ํ•œ Thread๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์š”์ฒญ(httpServletRequest) ๋ฐ ์‘๋‹ต(httpServletResponse) ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜์—ฌ ์ „๋‹ฌํ•œ๋‹ค. ํ˜ธ์ถœ๋œ ์„œ๋ธ”๋ฆฟ์˜ ์ž‘์—…์„ ๋‹ด๋‹นํ•˜๊ฒŒ ๋œ ์Šค๋ ˆ๋“œ๋Š” ๊ทธ์— ๋งž๋Š” doGet() ๋˜๋Š” doPost() ๋ฉ”์†Œ๋“œ๋ฅผ ํ˜ธ์ถœํ•ด ์ƒ์„ฑ๋œ ๋™์  ํŽ˜์ด์ง€๋ฅผ Response ๊ฐ์ฒด์— ๋‹ด์•„ ์ปจํ…Œ์ด๋„ˆ์— ์ „๋‹ฌํ•œ๋‹ค. ์ปจํ…Œ์ด๋„ˆ๋Š” ์ „๋‹ฌ ๋ฐ›์€ Response ๊ฐ์ฒด๋ฅผ HttpResponse ํ˜•ํƒœ๋กœ ๋ฐ”๊พธ์–ด Web Server์— ์ „๋‹ฌํ•˜๊ณ  ์ƒ์„ฑ๋œ.. 2022. 1. 24.