001/* 002 * Copyright 2012-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.boot.context.properties; 018 019import java.lang.annotation.Documented; 020import java.lang.annotation.ElementType; 021import java.lang.annotation.Retention; 022import java.lang.annotation.RetentionPolicy; 023import java.lang.annotation.Target; 024 025import org.springframework.core.annotation.AliasFor; 026 027/** 028 * Annotation for externalized configuration. Add this to a class definition or a 029 * {@code @Bean} method in a {@code @Configuration} class if you want to bind and validate 030 * some external Properties (e.g. from a .properties file). 031 * <p> 032 * Note that contrary to {@code @Value}, SpEL expressions are not evaluated since property 033 * values are externalized. 034 * 035 * @author Dave Syer 036 * @see ConfigurationPropertiesBindingPostProcessor 037 * @see EnableConfigurationProperties 038 */ 039@Target({ ElementType.TYPE, ElementType.METHOD }) 040@Retention(RetentionPolicy.RUNTIME) 041@Documented 042public @interface ConfigurationProperties { 043 044 /** 045 * The name prefix of the properties that are valid to bind to this object. Synonym 046 * for {@link #prefix()}. A valid prefix is defined by one or more words separated 047 * with dots (e.g. {@code "acme.system.feature"}). 048 * @return the name prefix of the properties to bind 049 */ 050 @AliasFor("prefix") 051 String value() default ""; 052 053 /** 054 * The name prefix of the properties that are valid to bind to this object. Synonym 055 * for {@link #value()}. A valid prefix is defined by one or more words separated with 056 * dots (e.g. {@code "acme.system.feature"}). 057 * @return the name prefix of the properties to bind 058 */ 059 @AliasFor("value") 060 String prefix() default ""; 061 062 /** 063 * Flag to indicate that when binding to this object invalid fields should be ignored. 064 * Invalid means invalid according to the binder that is used, and usually this means 065 * fields of the wrong type (or that cannot be coerced into the correct type). 066 * @return the flag value (default false) 067 */ 068 boolean ignoreInvalidFields() default false; 069 070 /** 071 * Flag to indicate that when binding to this object unknown fields should be ignored. 072 * An unknown field could be a sign of a mistake in the Properties. 073 * @return the flag value (default true) 074 */ 075 boolean ignoreUnknownFields() default true; 076 077}