
infra.beans.factory.annotation.Value Maven / Gradle / Ivy
/*
* Copyright 2017 - 2024 the original author or authors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see [https://www.gnu.org/licenses/]
*/
package infra.beans.factory.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import infra.beans.factory.config.BeanFactoryPostProcessor;
import infra.beans.factory.config.BeanPostProcessor;
import infra.beans.factory.support.AutowireCandidateResolver;
/**
* Annotation used at the field or method/constructor parameter level
* that indicates a default value expression for the annotated element.
*
* Typically used for expression-driven or property-driven dependency injection.
* Also supported for dynamic resolution of handler method arguments — for
* example, in Web MVC.
*
*
A common use case is to inject values using
* #{systemProperties.myProp}
style EL (SpEL)
* expressions. Alternatively, values may be injected using
* ${my.app.myProp}
style property placeholders.
*
*
Note that actual processing of the {@code @Value} annotation is performed
* by a {@link BeanPostProcessor BeanPostProcessor} which in turn means that you
* cannot use {@code @Value} within {@link BeanPostProcessor BeanPostProcessor} or
* {@link BeanFactoryPostProcessor BeanFactoryPostProcessor}
* types. Please consult the javadoc for the {@link
* AutowiredAnnotationBeanPostProcessor}
* class (which, by default, checks for the presence of this annotation).
*
* @author TODAY 2018-08-04 15:57
* @see Autowired
* @see AutowiredAnnotationBeanPostProcessor
* @see AutowireCandidateResolver#getSuggestedValue
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE })
public @interface Value {
/**
* The actual value expression such as #{systemProperties.myProp}
* or property placeholder such as ${my.app.myProp}
.
*/
String value();
}