@ConditionalOnProperty
Reference: Spring Docs - @ConditionalOnProperty
@ConditionalOnProperty ๋?
Spring Framework์์ ์ด๋ค Bean์ด ์์ฑ๋๊ฑฐ๋ ๊ตฌ์ฑ๋๊ธฐ ์ํ ์กฐ๊ฑด์ ์ง์ ํ๋๋ฐ ์ฌ์ฉ๋๋ ์กฐ๊ฑด๋ถ annotation
ํน์ property ๊ฐ์ ์ ๋ฌด๋ ๊ฐ์ ๋ฐ๋ผ Bean ์์ฑ ์ฌ๋ถ๋ฅผ ๊ฒฐ์ ํ ์ ์๋ค
@ConditionalOnProperty ์ ์์ฑ
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.METHOD })
@Documented
@Conditional(OnPropertyCondition.class)
public @interface ConditionalOnProperty {
/**
* Alias for {@link #name()}.
* @return the names
*/
String[] value() default {};
/**
* A prefix that should be applied to each property. The prefix automatically ends
* with a dot if not specified. A valid prefix is defined by one or more words
* separated with dots (e.g. {@code "acme.system.feature"}).
* @return the prefix
*/
String prefix() default "";
/**
* The name of the properties to test. If a prefix has been defined, it is applied to
* compute the full key of each property. For instance if the prefix is
* {@code app.config} and one value is {@code my-value}, the full key would be
* {@code app.config.my-value}
* <p>
* Use the dashed notation to specify each property, that is all lower case with a "-"
* to separate words (e.g. {@code my-long-property}).
* @return the names
*/
String[] name() default {};
/**
* The string representation of the expected value for the properties. If not
* specified, the property must <strong>not</strong> be equal to {@code false}.
* @return the expected value
*/
String havingValue() default "";
/**
* Specify if the condition should match if the property is not set. Defaults to
* {@code false}.
* @return if the condition should match if the property is missing
*/
boolean matchIfMissing() default false;
}
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?