์คํ๋ง ๋ถํธ ํ ์คํธ - ๋ด์ฅ ์๋ฒ ๋๋ค ํฌํธ๋ก ๋์ฐ๊ธฐ ์คํ๋ง ๋ถํธ ํ ์คํธ - ๋ด์ฅ ์๋ฒ ๋๋ค ํฌํธ๋ก ๋์ฐ๊ธฐ ๐ Dependency spring-boot 2.2.5.RELEASE junit 4.12 @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class WebtoonApiControllerTest { @LocalServerPort private int port; @Test public void printPort() throws Exception { System.out.println(port); assertNotEquals(port, 0); } @Autowired private TestRestTemplate.. 2020. 3. 24. [IntelliJ] ์คํ๋ง ๋ถํธ ์์ด ์คํ๋ง ์น MVC ํ๋ก์ ํธ ๋ง๋ค๊ณ ์ค์ ํ๊ธฐ [IntelliJ] ์คํ๋ง ๋ถํธ ์์ด ์คํ๋ง ์น MVC ํ๋ก์ ํธ ๋ง๋ค๊ณ ์ค์ ํ๊ธฐ โป ์ฌ์ฉ IDE : IntelliJ IDEA 2019.3 Ultimate 1. ์ ํ๋ก์ ํธ ์์ฑ ์ฌ์ฉํ๋ ๋น๋ํด(Maven, Gradle) ๊ธฐ๋ฐ์ ํ๋ก์ ํธ๋ฅผ ์์ฑํ๋ค. ์ ํ๋ก์ ํธ๋ฅผ ์์ฑํ๋ค. 1) ์ฌ์ฉํ ๋น๋ํด ์ ํ - ์ด ๊ธ์์๋ Maven์ ์ฌ์ฉํ๊ฒ ์ต๋๋ค. 2) ์ฌ์ฉํ JDK ์ ํ 3) Next ํด๋ฆญ ํ๋ก์ ํธ ์ ๋ณด๋ฅผ ์ ๋ ฅํ๊ณ Finish๋ฅผ ํด๋ฆญํด์ ํ๋ก์ ํธ ์์ฑ์ ์๋ฃํ๋ค. 2. ํ๋ก์ ํธ ์ธํ 1. Java Compiler ๋ฒ์ ๋ณ๊ฒฝ 2. ํ๋ก์ ํธ์ Web Facet ์ถ๊ฐ 3. war packaging ์ค์ Maven ํ๋ก์ ํธ๋ฅผ ์์ฑํ๋ฉด ๊ธฐ๋ณธ Java Compiler ๋ฒ์ ์ด 1.5๋ก ๋์ด์๊ธฐ ๋๋ฌธ์ ๋ณ๊ฒฝ์ด ํ์ํ๋ค. S.. 2020. 3. 17. Servlet์์ ์คํ๋ง ApplicationContext ์ฌ์ฉํ๊ธฐ Servlet์์ ์คํ๋ง ApplicationContext ์ฌ์ฉํ๊ธฐ pom.xml org.springframework spring-webmvc 5.1.3.RELEASE ์คํ๋ง ApplicationContext, ์ฆ ์คํ๋ง IoC๋ฅผ ์ฌ์ฉํ๋ ค๋ฉด ๊ด๋ จ ์์กด์ฑ์ ์ถ๊ฐํด์ผ ํ๋ค. spring-context ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ๊ฐ์ ธ์ฌ ์ ์๋๋ก ์์กด์ฑ์ ์ถ๊ฐํ๋ค. ์ ์์ ์์๋ spring-webmvc๋ฅผ ๊ฐ์ ธ์ค๋๋ก ํ์ง๋ง spring-context๋ง ๊ฐ์ ธ์๋ ๋๋ค. web.xml org.springframework.web.context.ContextLoaderListener contextClass org.springframework.web.context.support.AnnotationConfigWebApplication.. 2020. 3. 11. ์คํ๋ง ๋ถํธ์ ์์กด์ฑ ๊ด๋ฆฌ(Dependency Management) ์คํ๋ง ๋ถํธ์ ์์กด์ฑ ๊ด๋ฆฌ(Dependency Management) ๊ธฐ๋ณธ์ ์ธ ์คํ๋ง ๋ถํธ ํ๋ก์ ํธ์ pom.xml ํ์ผ์ ๋ณด๋ฉด ์์กด์ฑ ์ค์ ์ด spring-boot-starter-web๊ณผ spring-boot-starter-test ๋ ๊ฐ ๋ฟ์ด๊ณ ๋ฒ์ ๋ํ ๋ช ์ํ์ง ์๊ณ ์์ง๋ง ์ ๋ง์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ค์ ์์์ ๊ฐ์ ธ์จ๋ค. org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test org.junit.vintage junit-vintage-engine ์ด๊ฒ์ด ๊ฐ๋ฅํ ์ด์ ๋ ์คํ๋ง ๋ถํธ๊ฐ ์ ๊ณตํ๋ ์์กด์ฑ ๊ด๋ฆฌ ๊ธฐ๋ฅ ๋๋ฌธ์ด๋ค. ๊ธฐ๋ณธ ์คํ๋ง ๋ถํธ ํ๋ก์ ํธ๋ spring-boot-starter-.. 2020. 3. 11. ์คํ๋ง ๋ถํธ ํ๋ก์ ํธ ๋ง๋ค๊ธฐ - Spring Initializr ์น ๋๊ตฌ ์ฌ์ฉ ์คํ๋ง ๋ถํธ ํ๋ก์ ํธ ๋ง๋ค๊ธฐ - Spring Initializr ์น ๋๊ตฌ ์ฌ์ฉ ์คํ๋ง ํ๋ก์ ํธ๋ฅผ ๋ง๋๋ ๋ฐฉ๋ฒ ์ค์๋ Spring์์ ์ ๊ณตํ๋ Spring Initializr ์น ๋๊ตฌ๋ฅผ ์ฌ์ฉํ๋ ๊ฐํธํ ๋ฐฉ๋ฒ์ด ์๋ค. https://start.spring.io/ ์ ์ ์ํ์. ์ ์ฃผ์๋ก ๋ค์ด๊ฐ๋ฉด ์ด๋ฐ ํ๋ฉด์ด ๋ณด์ผ๊ฒ์ด๋ค. ์๊ฐ์ด ํ๋ฆ์ ๋ฐ๋ผ UI๋ ๋ฐ๋ ์ ์๋ค. ์ ํํด์ผํ๋ ์ต์ ์ ์ฐจ๋ก๋ก, Project: ์ฌ์ฉํ ๋น๋ ํด ์ ํ (Maven/Gradle) Maven, Gradle์ ํ๋ก์ ํธ์ ํ์ํ ์์กด์ฑ์ ๊ด๋ฆฌํ๊ณ ๋น๋ ๋ผ์ดํ์ฌ์ดํด์ ๊ด๋ฆฌํด์ฃผ๋ ํด์ด๋ค. ๊ณผ๊ฑฐ์๋ Maven์, ์ต๊ทผ์๋ Gradle์ ์ฌ์ฉํ๋ ์ถ์ธ์ด๋ค. ์คํ๋ง ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๊ด๋ฆฌ ์์ฒด๋ ์ต๊ทผ์๋ Gradle๋ก ํ๊ณ ์๋ค. Language: ์ธ์ด .. 2020. 3. 11. [Spring] SpEL - Spring Expression Language [Spring] SpEL - Spring Expression Language SpEL(Spring Expression Language)๋? Spring expression language๋ ๋ณดํต SpEL๋ก ํ๊ธฐํ๋ฉฐ ๊ตฌ๋๋ก๋ ์คํ๋ง EL์ด๋ผ๊ณ ์ง์นญํ๋ค. SpEL์ ๋ณดํต ๊ฐ์ฒด๋ฅผ ์กฐํํ๊ณ ์กฐ์ํ๋ ๊ธฐ๋ฅ์ ์ ๊ณตํ์ฌ Unified EL๊ณผ ์ ์ฌํ์ง๋ง ๋ฉ์๋ ํธ์ถ, ๋ฌธ์์ด ํ ํ๋ฆฟ ๊ธฐ๋ฅ ๋ฑ์ ์ฌ๋ฌ๊ฐ์ง ์ถ๊ฐ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ ํํ์ ์ธ์ด์ด๋ค. OGNL, MVEL, JBoss EL ๋ฑ ์๋ฐ์์ ์ฌ์ฉ๊ฐ๋ฅํ ์ฌ๋ฌ EL์ด ์์ง๋ง SpEL์ Spring ํ๋ก์ ํธ ์ ๋ฐ์ ๊ฑธ์ณ ์ฌ์ฉํ๊ธฐ ์ํด ๋ง๋ค์ด์ก์ผ๋ฉฐ ์คํ๋ง 3.0๋ถํฐ ์ง์๋๋ค. SpEL ํ๊ธฐ๋ฒ #{ SpELํํ์ } JSP์์ EL์ ์ฌ์ฉํด์ ๊ฐ์ฒด์ ํ๋กํผํฐ๋ฅผ ๊บผ๋ผ๋ ${ } ์ด.. 2020. 3. 7. [Spring] ๋ฐ์ดํฐ ๋ฐ์ธ๋ฉ - PropertyEditor, Converter ๊ทธ๋ฆฌ๊ณ Formatter [Spring] ๋ฐ์ดํฐ ๋ฐ์ธ๋ฉ - PropertyEditor, Converter ๊ทธ๋ฆฌ๊ณ Formatter 1. Data Binding(๋ฐ์ดํฐ ๋ฐ์ธ๋ฉ)์ ์ ์ ๐ ๋ฐ์ดํฐ ๋ฐ์ธ๋ฉ ์น์์ ์ฌ์ฉ์๊ฐ ์ ๋ ฅํ์ฌ ์ ๋ฌ๋๋ ๊ฐ์ ์ฃผ๋ก ๋ฌธ์์ด์ด๋ฉฐ, ์น ์ดํ๋ฆฌ์ผ์ด์ ์์๋ ์ด ๋ฌธ์์ด์ ๋๋ฉ์ธ ๊ฐ์ฒด์ ํ๋กํผํฐ ํ์ (int, date, boolean, ... ๋๋ ๋๋ฉ์ธ ๊ฐ์ฒด ํ์ ๊ทธ ์์ฒด)์ผ๋ก ๋ณํ์ด ํ์ํ๋ค. ์ด๋ ๊ฒ ์ฌ์ฉ์๊ฐ ์ ๋ ฅํ ๋ฌธ์์ด ๊ฐ์ ํ๋กํผํฐ ํ์ ์ ๋ง์ถฐ ๋ณํํ์ฌ ํ ๋นํ๋ ๊ฒ์ ๋ฐ์ดํฐ ๋ฐ์ธ๋ฉ์ด๋ผ ํ๋ค. 2. Spring์ ๋ฐ์ดํฐ ๋ฐ์ธ๋ฉ Spring์ ๋ฐ์ดํฐ ๋ฐ์ธ๋ฉ ๊ธฐ๋ฅ์ ์ฌ๋ฌ ์ธํฐํ์ด์ค๋ก ์ถ์ํํ์ฌ ์ ๊ณตํ๋ค. ๋ฐ์ดํฐ ๋ฐ์ธ๋ฉ ์ธํฐํ์ด์ค๋ ์ฃผ๋ก ์น MVC์์ ์ฌ์ฉํ์ง๋ง web์ ๊ตญํ๋์ด ํนํ๋ ๊ธฐ๋ฅ์ด ์๋๋ผ ์ฌ๋ฌ ๊ณณ.. 2020. 3. 6. [Spring] Validation ์ถ์ํ [Spring] Validation ์ถ์ํ org.springframework.validation.Validator๋ spring์์ ์ ๊ณตํ๋ ๊ฐ์ฒด ๊ฒ์ฆ์ฉ ์ธํฐํ์ด์ค์ด๋ค. ์ฃผ๋ก spring mvc์์ ์ฌ์ฉํ์ง๋ง web ๊ณ์ธต ์ ์ฉ ๊ฐ๋ ์ ์๋๋ฉฐ ์ผ๋ฐ์ ์ผ๋ก ์ฌ์ฉ๋ ์ ์๋ค. Validator๋ Java EE ํ์ค ์คํ ์ค ํ๋์ธ Bean Validation์ ์ง์ํ์ฌ Bean Validation์ด ์ ๊ณตํ๋ ์ฌ๋ฌ ์ ๋ ธํ ์ด์ ๋ค์ ์ฌ์ฉํด์ ๊ฐ์ฒด ๋ฐ์ดํฐ๋ฅผ ๊ฒ์ฆํ ์ ์๋ค. 1. Validator ์ธํฐํ์ด์ค Validator ์ธํฐํ์ด์ค์๋ ๋ ๊ฐ์ง ๋ฉ์๋๊ฐ ์ ์๋์ด์๋ค. 1 2 3 4 5 6 boolean supports(Class clazz) { // ์ธ์คํด์ค๊ฐ ๊ฒ์ฆ ๋์ ํ์ ์ธ์ง ํ์ธ } void validate.. 2020. 3. 5. [Spring] Resource ์ถ์ํ [Spring] Resource ์ถ์ํ Spring์ java.net.URL์ org.springframework.core.io.Resource๋ก ๊ฐ์ธ์ ์ถ์ํํ ํด๋์ค๋ฅผ ์ ๊ณตํ๋ค. ์ดํ๋ฆฌ์ผ์ด์ ์์ ์ฌ์ฉํ๋ ๋ฆฌ์์ค ์์ฒด๋ฅผ ์ถ์ํ ํ๊ฒ์ธ๋ฐ spring์์ ์ด๋ฅผ ์ถ์ํํ ์ด์ ๋ ๋ค์๊ณผ ๊ฐ๋ค. java.net.URL์ http, https, ftp๋ ์ง์ํ์ง๋ง classpath๋ฅผ ๊ธฐ์ค์ผ๋ก ๋ฆฌ์์ค๋ฅผ ๊ฐ์ ธ์ค๋ ๊ธฐ๋ฅ์ด ์๋ค. ServletContext๋ฅผ ๊ธฐ์ค์ผ๋ก ์๋ ๊ฒฝ๋ก๋ก ๋ฆฌ์์ค๋ฅผ ๊ฐ์ ธ์ค๋ ๊ธฐ๋ฅ์ด ์๋ค. ์๋ก์ด ํธ๋ค๋ฌ๋ฅผ ๋ฑ๋กํ์ฌ URL ์ ๋ฏธ์ฌ๋ฅผ ๋ง๋ค์ด ์ฌ์ฉํ ์๋ ์์ง๋ง ๊ตฌํ์ด ๋ณต์กํ๊ณ ํธ์์ฑ ๋ฉ์๋๊ฐ ๋ถ์กฑํ๋ค. Spring์ ๋ฆฌ์์ค๋ฅผ ์ถ์ํํ์ฌ ๋ฆฌ์์ค๋ฅผ ๋ค๋ฃจ๋๋ฐ ์์ด ํ๋์ ํต์ผ๋ ์ธํฐํ์ด์ค๋ฅผ ์ ๊ณตํ๋ค. 1. S.. 2020. 3. 5. [Spring] ResourceLoader๋ก ํ ์คํธ ํ์ผ ์ถ๋ ฅํ๊ธฐ (Java 11) [Spring] ResourceLoader๋ก ํ ์คํธ ํ์ผ ์ถ๋ ฅํ๊ธฐ (Java 11) Spring์ ApplicationContext๋ ResourceLoader๋ผ๋ ์ธํฐํ์ด์ค๋ฅผ ์์ํ๋ค. ์ด ์ธํฐํ์ด์ค๋ ์ด๋ฆ์์๋ถํฐ ์ ์ ์๋ฏ ๋ฆฌ์์ค๋ฅผ ์ฝ์ด์ค๋ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ค. 1. Resource ๊ฐ์ฒด ์ป๊ธฐ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.sprin.. 2020. 3. 5. [Spring] ApplicationEventPublisher๋ฅผ ์ด์ฉํ ์ด๋ฒคํธ ํ๋ก๊ทธ๋๋ฐ [Spring] ApplicationEventPublisher๋ฅผ ์ด์ฉํ ์ด๋ฒคํธ ํ๋ก๊ทธ๋๋ฐ ApplicationEventPublisher๋ Spring์ ApplicationContext๊ฐ ์์ํ๋ ์ธํฐํ์ด์ค ์ค ํ๋์ด๋ค. ์ต์ ๋ฒ ํจํด์ ๊ตฌํ์ฒด๋ก ์ด๋ฒคํธ ํ๋ก๊ทธ๋๋ฐ์ ํ์ํ ๊ธฐ๋ฅ์ ์ ๊ณตํด์ค๋ค. 1. ApplicationEvent๋ฅผ ์์ํ๋ ์ด๋ฒคํธ ํด๋์ค ๋ง๋ค๊ธฐ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 import org.springframework.context.ApplicationEvent; public class MyEvent extends ApplicationEvent { private int data; public MyEvent(Object source) .. 2020. 3. 5. [Spring] Spring ์ดํ๋ฆฌ์ผ์ด์ ๋ฉ์์ง ๋ค๊ตญ์ด ๋ฐ ์ฌ๋ก๋ฉ ์ฒ๋ฆฌ [Spring] Spring ์ดํ๋ฆฌ์ผ์ด์ ๋ฉ์์ง ๋ค๊ตญ์ด ๋ฐ ์ฌ๋ก๋ฉ ์ฒ๋ฆฌ Spring IoC ์ปจํ ์ด๋ = ApplicationContext๊ฐ ๊ฐ๊ณ ์๋ ๊ธฐ๋ฅ ์ค MessageSource๋ ๊ตญ์ ํ(i18n)์ ๊ด๋ จ๋ ๊ธฐ๋ฅ์ ์ ๊ณตํด์ฃผ๋๋ฐ ์ด๋ฅผ ์ด์ฉํด์ ์ดํ๋ฆฌ์ผ์ด์ ์์ ์ถ๋ ฅํ๋ ๋ฉ์์ง๋ฅผ ๋ค๊ตญํํ ์ ์๋ค. 1. ๋ฉ์์ง ํ์ผ ์์ฑ resources ๋๋ ํ ๋ฆฌ ์๋์ messages.properties, messages_ko_KR.properties ํ์ผ์ ์๋ก ์์ฑํ๋ค. ์ฌ๊ธฐ์ ์ดํ๋ฆฌ์ผ์ด์ ์์ ์ถ๋ ฅํ ๋ฉ์์ง๋ฅผ messages.properties์๋ ์์ด๋ก, messages_ko_KR.proeprties์๋ ํ๊ตญ์ด๋ก ์์ฑํ ๊ฒ์ด๋ค. ํ์ผ๋ช ์ ์คํ๊ฐ ๋์ง ์๋๋ก ์กฐ์ฌํ์. ํ์ผ์ ์์ฑํ๊ณ ๋๋ฉด ์๋์ผ๋ก 'messages.. 2020. 3. 4. ์ด์ 1 2 3 4 5 ๋ค์