001/*
002 * Copyright 2002-2020 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 *      https://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.beans.factory.annotation;
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
025/**
026 * Annotation used at the field or method/constructor parameter level
027 * that indicates a default value expression for the annotated element.
028 *
029 * <p>Typically used for expression-driven or property-driven dependency injection.
030 * Also supported for dynamic resolution of handler method arguments &mdash; for
031 * example, in Spring MVC.
032 *
033 * <p>A common use case is to inject values using
034 * <code>#{systemProperties.myProp}</code> style SpEL (Spring Expression Language)
035 * expressions. Alternatively, values may be injected using
036 * <code>${my.app.myProp}</code> style property placeholders.
037 *
038 * <p>Note that actual processing of the {@code @Value} annotation is performed
039 * by a {@link org.springframework.beans.factory.config.BeanPostProcessor
040 * BeanPostProcessor} which in turn means that you <em>cannot</em> use
041 * {@code @Value} within
042 * {@link org.springframework.beans.factory.config.BeanPostProcessor
043 * BeanPostProcessor} or
044 * {@link org.springframework.beans.factory.config.BeanFactoryPostProcessor BeanFactoryPostProcessor}
045 * types. Please consult the javadoc for the {@link AutowiredAnnotationBeanPostProcessor}
046 * class (which, by default, checks for the presence of this annotation).
047 *
048 * @author Juergen Hoeller
049 * @since 3.0
050 * @see AutowiredAnnotationBeanPostProcessor
051 * @see Autowired
052 * @see org.springframework.beans.factory.config.BeanExpressionResolver
053 * @see org.springframework.beans.factory.support.AutowireCandidateResolver#getSuggestedValue
054 */
055@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE})
056@Retention(RetentionPolicy.RUNTIME)
057@Documented
058public @interface Value {
059
060        /**
061         * The actual value expression such as <code>#{systemProperties.myProp}</code>
062         * or property placeholder such as <code>${my.app.myProp}</code>.
063         */
064        String value();
065
066}