[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. [Spring] EnvironmentCapable - Property ์ฌ์ฉํ๊ธฐ ๊ด๋ จ ๊ธ - JAVA ์น ํ๋ก์ ํธ์์ Properties ํ์ผ ํ์ฉํ๊ธฐ - [Spring] EnvironmentCapable - Profile ์ฌ์ฉํ๊ธฐ [Spring] EnvironmentCapable - Property ์ฌ์ฉํ๊ธฐ ApplicationContext๋ EnvironmentCapable์ ์์๋ฐ์ผ๋ฉฐ, EnvironmentCapable์ด ์ ๊ณตํ๋ ์ฃผ์ ๊ธฐ๋ฅ์๋ profile๊ณผ property๊ฐ ์๋ค. ๋ณธ ํฌ์คํ ์์๋ ๊ทธ ์ค property์ ๋ํด ์ดํด๋ณธ๋ค. 1. Property ๊ธฐ๋ฅ ์ดํ๋ฆฌ์ผ์ด์ ์์ ์ฌ์ฉ๋๋ ์ฌ๋ฌ๊ฐ์ง key, value ์์ผ๋ก ์ ๊ณต๋๋ ํ๋กํผํฐ์ ๊ฐํธํ๊ฒ ์ ๊ทผํ ์ ์๋ ๊ธฐ๋ฅ์ด๋ค. Spring์ ํ๋กํผํฐ์ '๊ณ์ธตํ'์ผ๋ก ์ ๊ทผํ๋๋ฐ ๊ณ์ธตํ์ผ๋ก ์ ๊ทผํ๋ค๋ ๋ง์ ํ๋กํผํฐ์ ์ฐ์ ์์๊ฐ.. 2020. 3. 4. [Spring] EnvironmentCapable - Profile ์ฌ์ฉํ๊ธฐ [Spring] EnvironmentCapable - Profile ์ฌ์ฉํ๊ธฐ Spring์ ApplicationContext๋ BeanFactory ๊ธฐ๋ฅ๋ง ํ๋๊ฑด ์๋๋ค. ApplicationContext๊ฐ ์์๋ฐ๋ ๋ค์ํ ์ธํฐํ์ด์ค๋ค ์ค EnvironmentCapable ์ธํฐํ์ด์ค๋ 'Profile(ํ๋กํ์ผ)' ์ด๋ผ๋ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ค. Profile(ํ๋กํ์ผ)์ ๊ฐ๋ ํ๋กํ์ผ = ๋น๋ค์ ๋ฌถ์ ํ๋กํ์ผ์ ํน์ ์คํ ํ๊ฒฝ์์ ์ฌ์ฉํ ๋น๋ค์ ๋ฌถ์์ด๋ค. ํ ์คํธ ํ๊ฒฝ์์ ์ฌ์ฉํ ๋น ๋ฌถ์๊ณผ ํ๋ก๋์ (์ด์) ํ๊ฒฝ์์ ์ฌ์ฉํ ๋น ๋ฌถ์์ด ์๋ก ๋ค๋ฅผ ์ ์๋ค. ๋ ๊ฐ ํ๊ฒฝ์ ๋ฐ๋ผ ์๋ก ๋ค๋ฅธ ๋น๋ค์ ์จ์ผํ๋ ๊ฒฝ์ฐ, ํน์ ํ๊ฒฝ์์๋ง ๋ฑ๋กํด์ผํ๋ ๋น๋ค์ด ์๋ ๊ฒฝ์ฐ๊ฐ ์์ ์ ์๋ค. ํ๋กํ์ผ์ ๊ทธ๋ฌํ ์๊ตฌ์ฌํญ์ ์ถฉ์กฑํ ์ ์๋.. 2020. 3. 4. [Git] Git Bash ์ฌ์ฉ ๋ฐฉ๋ฒ - init, status, add, commit, log [Git] Git Bash ์ฌ์ฉ ๋ฐฉ๋ฒ - init, status, add, commit, log Git์ ์ฌ์ฉํ๋ ค๋ฉด ์ฌ์ฉํ๋ ํ๋ซํผ์ ๋ง๋ git์ ๋ค์ด๋ก๋๋ฐ๊ณ ์ค์นํด์ผํ๋ค. ์๋์ฐ์ git์ ์ค์นํ๋ ค๋ฉด ๋ค์ ํฌ์คํธ๋ฅผ ์ฐธ๊ณ ํ๋ค. - ์๋์ฐ์ฉ Git ๋ค์ด๋ก๋ ๋ฐ ์ค์นํ๊ธฐ - ์ค์น ์ต์ ์ ๋ํ ์์ธํ ์ค๋ช ํฌํจ 1. Git ์ ์ฅ์ ๋ง๋ค๊ธฐ - git init ๋ค์ ์ค ํ ๊ฐ์ง ๋ฐฉ๋ฒ์ผ๋ก Git ์ ์ฅ์๋ฅผ ๋ง๋ค์ ์๋ค. ์์ง ๋ฒ์ ๊ด๋ฆฌ๋ฅผ ํ์ง ์๋ ๋ก์ปฌ ๋๋ ํ ๋ฆฌ ํ๋๋ฅผ ์ ํํด์ Git ์ ์ฅ์๋ฅผ ์ ์ฉํ๋ ๋ฐฉ๋ฒ ๋ค๋ฅธ ์ด๋๊ฐ์์ Git ์ ์ฅ์๋ฅผ Clone ํ๋ ๋ฐฉ๋ฒ ์ฌ๊ธฐ์๋ ๊ธฐ์กด์ ๋ก์ปฌ ๋๋ ํ ๋ฆฌ๋ฅผ git ์ ์ฅ์๋ก ๋ง๋๋ ๋ฐฉ๋ฒ์ ์์๋ณธ๋ค. Git ์ ์ฅ์๋ก ๋ง๋ค ํด๋๋ก ์ด๋ํด์ ๋ง์ฐ์ค ์ฐ์ธก ๋ฒํผ์ ๋๋ฅด๊ณ Git Bash He.. 2020. 3. 4. [Spring] ๋น์ Scope - ์ฑ๊ธํค๊ณผ ํ๋กํ ํ์ [Spring] ๋น์ Scope - ์ฑ๊ธํค๊ณผ ํ๋กํ ํ์ ๋น์ ๋ฑ๋กํ ๋ ์๋ฌด๋ฐ ์ค์ ์ ํ์ง ์์ผ๋ฉด ๊ธฐ๋ณธ์ ์ผ๋ก ๋น์ ์ฑ๊ธํค scope์ ๊ฐ๋๋ค. ์ฑ๊ธํค scope์ด๋ ์ดํ๋ฆฌ์ผ์ด์ ์ ๋ฐ์ ๊ฑธ์ณ ํด๋น ๋น์ ์ธ์คํด์ค๋ฅผ ์ค์ง ํ๋๋ง ์์ฑํด์ ์ฌ์ฉํ๋ ๊ฒ์ด๋ค. 1. Singleton Scope Single, Proto ํด๋์ค๋ฅผ ์๋ก ๋ง๋ค๊ณ @Component๋ฅผ ๋ถ์ฌ ๋น์ผ๋ก ๋ฑ๋กํ๋ค. Single.java 1 2 3 4 5 6 7 8 9 10 11 12 13 import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component public class Single { @.. 2020. 3. 3. [IntelliJ] ์ ์ฉํ ๋จ์ถํค - import๋ฌธ ์ ๋ฆฌํ๊ธฐ [IntelliJ] ์ ์ฉํ ๋จ์ถํค - import๋ฌธ ์ ๋ฆฌํ๊ธฐ ์ด ํด๋์ค์์ ํ์์ผ๋ก ํ์๋ import๋ฌธ๋ค์ ๋ชจ๋ ์ฌ์ฉํ์ง ์๋ import๋ฌธ๋ค์ด๋ค. ์๋์ผ๋ก ์ง์ ์ง์ฐ๋ ๋ฐฉ๋ฒ๋ ์๊ฒ ์ง๋ง ๋จ์ถํค๋ฅผ ์ฌ์ฉํ๋ฉด ์ฌ์ฉํ์ง ์๋ import๋ฌธ๋ค์ ์ฆ์ ์๋์ผ๋ก ์ ๋ฆฌํ ์ ์๋ค. โจ ์ฌ์ฉํ์ง ์๋ import๋ฌธ์ ์ ๋ฆฌํ๋ ๋จ์ถํค ์๋์ฐ : Ctrl + Alt + O Mac OS : ^ + โฅ + O ๊ทธ๋์ ์ ์ํ์์ import๋ฌธ ์ ๋ฆฌ ๋จ์ถํค๋ฅผ ๋๋ฌ์ฃผ๋ฉด, ์ฆ์ ์ด๋ ๊ฒ import๋ฌธ์ด ์ ๋ฆฌ๋๋ค. ์ฐธ๊ณ ๋ก Settings์์ ํ์ธํ ์ ์๋ ์ด ๋จ์ถํค์ ์ ์ ๋ช ์นญ์ Optimize Imports์ด๋ค. 2020. 3. 2. ์ด์ 1 ยทยทยท 5 6 7 8 9 10 11 ยทยทยท 17 ๋ค์