@ConditionalOnProperty
Reference: Spring Docs - @ConditionalOnProperty
@ConditionalOnProperty ๋?
Spring Framework์์ ์ด๋ค Bean์ด ์์ฑ๋๊ฑฐ๋ ๊ตฌ์ฑ๋๊ธฐ ์ํ ์กฐ๊ฑด์ ์ง์ ํ๋๋ฐ ์ฌ์ฉ๋๋ ์กฐ๊ฑด๋ถ annotation
ํน์ property ๊ฐ์ ์ ๋ฌด๋ ๊ฐ์ ๋ฐ๋ผ Bean ์์ฑ ์ฌ๋ถ๋ฅผ ๊ฒฐ์ ํ ์ ์๋ค
@ConditionalOnProperty ์ ์์ฑ
Default value
property๊ฐ Environment ์ ์กด์ฌํ๊ณ ,
false๊ฐ ์๋๋ค
Optional Elements
name
(ํ์ ์์ฑ) - String[]test ํ๊ณ ์ ํ๋ property ์ ์ด๋ฆ์ ์ง์ ํ๋ค
havingValue
- Stringํด๋น property๊ฐ ๊ฐ์ง๊ณ ์์ด์ผ ํ๋ attribute๋ฅผ ๋ช ์ํ๋ค
property ๊ฐ๊ณผ ๋น๊ตํ ๊ฐ์ ์ง์ !
์ ํ์ ์ผ๋ก ์ฌ์ฉํ ์ ์์ผ๋ฉฐ, default ๊ฐ์ empty string (โโ)์ด๋ค
ํด๋น ๊ฐ์ด ์ง์ ํ์ง ์๊ฑฐ๋ empty string์ผ๋ก ์์ฑํ๋ฉด, property ๊ฐ์ด ์ด๋ค ๊ฐ์ด๋ ์๊ด ์์ด property๊ฐ ์ค์ ๋๊ธฐ๋ง ํ๋ฉด Bean์ด ์์ฑ๋๋ค
๊ฐ์ด ์ง์ ๋ ๊ฒฝ์ฐ (not empty string), ์ง์ ํ ๊ฐ๊ณผ property ๊ฐ์ด ์ผ์นํด์ผ Bean์ด ์์ฑ๋๋ค
matchIfMissing
- booleanํด๋น property ๊ฐ ์์ Environment์ ์กด์ฌํ์ง ์์ ๋ ์กฐ๊ฑด์ ๋ง์กฑํ ์ง ์ฌ๋ถ๋ฅผ ๊ฒฐ์ ํ๋ค
default ๊ฐ์
false
์ด๊ณ , property๊ฐ ์ค์ ๋์ง ์์ผ๋ฉด Bean์ด ์์ฑ๋์ง ์๋๋คtrue
๋ก ์ค์ ํ๋ฉด property๊ฐ ์ค์ ๋์ง ์์ ๊ฒฝ์ฐ์๋ Bean์ด ์์ฑ๋๋ค
prefix
- String๊ฐ๊ฐ์ property์ ์ ์ฉํ๊ณ ์ ํ๋ prefix๋ฅผ ์ง์ ํ๋ค
์ด ์์ฑ์ ์ฌ์ฉํ๋ฉด ์ฌ๋ฌ property๋ค์ ๋ํด ๊ณตํต๋ prefix๋ฅผ ์ฌ์ฉํ์ฌ ์กฐ๊ฑด์ ์ง์ ํ ์ ์๋ค
value
- String[]name() ์ alias
Last updated
Was this helpful?