/* * Copyright 2002-2013 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */
package org.springframework.context.annotation;
/** * Enumeration of the type filters that may be used in conjunction with * {@link ComponentScan @ComponentScan}. * * @author Mark Fisher * @author Juergen Hoeller * @author Chris Beams * @since 2.5 * @see ComponentScan * @see ComponentScan#includeFilters() * @see ComponentScan#excludeFilters() * @see org.springframework.core.type.filter.TypeFilter */ publicenumFilterType {
/** * Filter candidates marked with a given annotation. * @see org.springframework.core.type.filter.AnnotationTypeFilter */ ANNOTATION,
/** * Filter candidates assignable to a given type. * @see org.springframework.core.type.filter.AssignableTypeFilter */ ASSIGNABLE_TYPE,
/** * Filter candidates matching a given AspectJ type pattern expression. * @see org.springframework.core.type.filter.AspectJTypeFilter */ ASPECTJ,
/** * Filter candidates matching a given regex pattern. * @see org.springframework.core.type.filter.RegexPatternTypeFilter */ REGEX,
/** Filter candidates using a given custom * {@link org.springframework.core.type.filter.TypeFilter} implementation. */ CUSTOM
/* * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */
/** * When used as a type-level annotation in conjunction with * {@link org.springframework.stereotype.Component @Component}, * {@code@Scope} indicates the name of a scope to use for instances of * the annotated type. * * <p>When used as a method-level annotation in conjunction with * {@link Bean @Bean}, {@code@Scope} indicates the name of a scope to use * for the instance returned from the method. * * <p>In this context, <em>scope</em> means the lifecycle of an instance, * such as {@code singleton}, {@code prototype}, and so forth. Scopes * provided out of the box in Spring may be referred to using the * {@code SCOPE_*} constants available in the {@link ConfigurableBeanFactory} * and {@code WebApplicationContext} interfaces. * * <p>To register additional custom scopes, see * {@link org.springframework.beans.factory.config.CustomScopeConfigurer * CustomScopeConfigurer}. * * @author Mark Fisher * @author Chris Beams * @author Sam Brannen * @since 2.5 * @see org.springframework.stereotype.Component * @see org.springframework.context.annotation.Bean */ @Target({ElementType.TYPE, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @Documented public@interface Scope {
/** * Alias for {@link #scopeName}. * @see #scopeName */ @AliasFor("scopeName") String value()default"";
/** * Specifies the name of the scope to use for the annotated component/bean. * <p>Defaults to an empty string ({@code ""}) which implies * {@link ConfigurableBeanFactory#SCOPE_SINGLETON SCOPE_SINGLETON}. * @since 4.2 * @see ConfigurableBeanFactory#SCOPE_PROTOTYPE * @see ConfigurableBeanFactory#SCOPE_SINGLETON * @see org.springframework.web.context.WebApplicationContext#SCOPE_REQUEST * @see org.springframework.web.context.WebApplicationContext#SCOPE_SESSION * @see #value */ @AliasFor("value") String scopeName()default"";
/** * Specifies whether a component should be configured as a scoped proxy * and if so, whether the proxy should be interface-based or subclass-based. * <p>Defaults to {@link ScopedProxyMode#DEFAULT}, which typically indicates * that no scoped proxy should be created unless a different default * has been configured at the component-scan instruction level. * <p>Analogous to {@code <aop:scoped-proxy/>} support in Spring XML. * @see ScopedProxyMode */ ScopedProxyMode proxyMode()default ScopedProxyMode.DEFAULT;
/** * All {@link Condition}s that must {@linkplain Condition#matches match} * in order for the component to be registered. */ Class<? extendsCondition>[] value();
/** * Determine if the condition matches. * @param context the condition context * @param metadata metadata of the {@link org.springframework.core.type.AnnotationMetadata class} * or {@link org.springframework.core.type.MethodMetadata method} being checked. * @return {@code true} if the condition matches and the component can be registered * or {@code false} to veto registration. */ booleanmatches(ConditionContext context, AnnotatedTypeMetadata metadata);
/** * {@link Configuration}, {@link ImportSelector}, {@link ImportBeanDefinitionRegistrar} * or regular component classes to import. */ Class<?>[] value();
}
查看ImportSelector源码:
1 2 3 4 5 6 7 8 9
publicinterfaceImportSelector {
/** * Select and return the names of which class(es) should be imported based on * the {@link AnnotationMetadata} of the importing @{@link Configuration} class. */ String[] selectImports(AnnotationMetadata importingClassMetadata);
}
Select and return the names of which class(es) should be imported
/** * Register bean definitions as necessary based on the given annotation metadata of * the importing {@code@Configuration} class. * <p>Note that {@link BeanDefinitionRegistryPostProcessor} types may <em>not</em> be * registered here, due to lifecycle constraints related to {@code@Configuration} * class processing. * @param importingClassMetadata annotation metadata of the importing class * @param registry current bean definition registry */ publicvoidregisterBeanDefinitions( AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry);
/** * Return an instance (possibly shared or independent) of the object * managed by this factory. * <p>As with a {@link BeanFactory}, this allows support for both the * Singleton and Prototype design pattern. * <p>If this FactoryBean is not fully initialized yet at the time of * the call (for example because it is involved in a circular reference), * throw a corresponding {@link FactoryBeanNotInitializedException}. * <p>As of Spring 2.0, FactoryBeans are allowed to return {@code null} * objects. The factory will consider this as normal value to be used; it * will not throw a FactoryBeanNotInitializedException in this case anymore. * FactoryBean implementations are encouraged to throw * FactoryBeanNotInitializedException themselves now, as appropriate. * @return an instance of the bean (can be {@code null}) * @throws Exception in case of creation errors * @see FactoryBeanNotInitializedException */ T getObject()throws Exception;
/** * Return the type of object that this FactoryBean creates, * or {@code null} if not known in advance. * <p>This allows one to check for specific types of beans without * instantiating objects, for example on autowiring. * <p>In the case of implementations that are creating a singleton object, * this method should try to avoid singleton creation as far as possible; * it should rather estimate the type in advance. * For prototypes, returning a meaningful type here is advisable too. * <p>This method can be called <i>before</i> this FactoryBean has * been fully initialized. It must not rely on state created during * initialization; of course, it can still use such state if available. * <p><b>NOTE:</b> Autowiring will simply ignore FactoryBeans that return * {@code null} here. Therefore it is highly recommended to implement * this method properly, using the current state of the FactoryBean. * @return the type of object that this FactoryBean creates, * or {@code null} if not known at the time of the call * @see ListableBeanFactory#getBeansOfType */ Class<?> getObjectType();
/** * Is the object managed by this factory a singleton? That is, * will {@link #getObject()} always return the same object * (a reference that can be cached)? * <p><b>NOTE:</b> If a FactoryBean indicates to hold a singleton object, * the object returned from {@code getObject()} might get cached * by the owning BeanFactory. Hence, do not return {@code true} * unless the FactoryBean always exposes the same reference. * <p>The singleton status of the FactoryBean itself will generally * be provided by the owning BeanFactory; usually, it has to be * defined as singleton there. * <p><b>NOTE:</b> This method returning {@code false} does not * necessarily indicate that returned objects are independent instances. * An implementation of the extended {@link SmartFactoryBean} interface * may explicitly indicate independent instances through its * {@link SmartFactoryBean#isPrototype()} method. Plain {@link FactoryBean} * implementations which do not implement this extended interface are * simply assumed to always return independent instances if the * {@code isSingleton()} implementation returns {@code false}. * @return whether the exposed object is a singleton * @see #getObject() * @see SmartFactoryBean#isPrototype() */ booleanisSingleton();
}
可以看到有三个方法:
T getObject() throws Exception: 返回需要放到容器中的对象,这里是泛型也就是说工厂接口在实现时就已经确定了其只能返回某种类型的对象了
/** * Used to dereference a {@link FactoryBean} instance and distinguish it from * beans <i>created</i> by the FactoryBean. For example, if the bean named * {@code myJndiObject} is a FactoryBean, getting {@code &myJndiObject} * will return the factory, not the instance returned by the factory. */ StringFACTORY_BEAN_PREFIX="&"; //... }
/** * Invoked by a BeanFactory after it has set all bean properties supplied * (and satisfied BeanFactoryAware and ApplicationContextAware). * <p>This method allows the bean instance to perform initialization only * possible when all bean properties have been set and to throw an * exception in the event of misconfiguration. * @throws Exception in the event of misconfiguration (such * as failure to set an essential property) or if initialization fails. */ voidafterPropertiesSet()throws Exception;
}
与之相对的在bean销毁时也有对应的接口:
1 2 3 4 5 6 7 8 9 10 11
publicinterfaceDisposableBean {
/** * Invoked by a BeanFactory on destruction of a singleton. * @throws Exception in case of shutdown errors. * Exceptions will get logged but not rethrown to allow * other beans to release their resources too. */ voiddestroy()throws Exception;
/** * The PostConstruct annotation is used on a method that needs to be executed * after dependency injection is done to perform any initialization. This * method MUST be invoked before the class is put into service. This * annotation MUST be supported on all classes that support dependency * injection. The method annotated with PostConstruct MUST be invoked even * if the class does not request any resources to be injected. Only one * method can be annotated with this annotation. The method on which the * PostConstruct annotation is applied MUST fulfill all of the following * criteria: * <p> * <ul> * <li>The method MUST NOT have any parameters except in the case of * interceptors in which case it takes an InvocationContext object as * defined by the Interceptors specification.</li> * <li>The method defined on an interceptor class MUST HAVE one of the * following signatures: * <p> * void <METHOD>(InvocationContext) * <p> * Object <METHOD>(InvocationContext) throws Exception * <p> * <i>Note: A PostConstruct interceptor method must not throw application * exceptions, but it may be declared to throw checked exceptions including * the java.lang.Exception if the same interceptor method interposes on * business or timeout methods in addition to lifecycle events. If a * PostConstruct interceptor method returns a value, it is ignored by * the container.</i> * </li> * <li>The method defined on a non-interceptor class MUST HAVE the * following signature: * <p> * void <METHOD>() * </li> * <li>The method on which PostConstruct is applied MAY be public, protected, * package private or private.</li> * <li>The method MUST NOT be static except for the application client.</li> * <li>The method MAY be final.</li> * <li>If the method throws an unchecked exception the class MUST NOT be put into * service except in the case of EJBs where the EJB can handle exceptions and * even recover from them.</li></ul> * @since Common Annotations 1.0 * @see javax.annotation.PreDestroy * @see javax.annotation.Resource */ @Documented @Retention (RUNTIME) @Target(METHOD) public@interface PostConstruct { }
The PostConstruct annotation is used on a method that needs to be executed after dependency injection is done to perform any initialization.
/** * The PreDestroy annotation is used on methods as a callback notification to * signal that the instance is in the process of being removed by the * container. The method annotated with PreDestroy is typically used to * release resources that it has been holding. This annotation MUST be * supported by all container managed objects that support PostConstruct * except the application client container in Java EE 5. The method on which * the PreDestroy annotation is applied MUST fulfill all of the following * criteria: * <p> * <ul> * <li>The method MUST NOT have any parameters except in the case of * interceptors in which case it takes an InvocationContext object as * defined by the Interceptors specification.</li> * <li>The method defined on an interceptor class MUST HAVE one of the * following signatures: * <p> * void <METHOD>(InvocationContext) * <p> * Object <METHOD>(InvocationContext) throws Exception * <p> * <i>Note: A PreDestroy interceptor method must not throw application * exceptions, but it may be declared to throw checked exceptions including * the java.lang.Exception if the same interceptor method interposes on * business or timeout methods in addition to lifecycle events. If a * PreDestroy interceptor method returns a value, it is ignored by * the container.</i> * </li> * <li>The method defined on a non-interceptor class MUST HAVE the * following signature: * <p> * void <METHOD>() * </li> * <li>The method on which PreDestroy is applied MAY be public, protected, * package private or private.</li> * <li>The method MUST NOT be static.</li> * <li>The method MAY be final.</li> * <li>If the method throws an unchecked exception it is ignored except in the * case of EJBs where the EJB can handle exceptions.</li> * </ul> * * @see javax.annotation.PostConstruct * @see javax.annotation.Resource * @since Common Annotations 1.0 */
The PreDestroy annotation is used on methods as a callback notification to signal that the instance is in the process of being removed by the container.
显然被注解方法会在 being removed by the container之前做为callback notification to signal被调用,即容器销毁bean之前调用该方法
/** * Apply this BeanPostProcessor to the given new bean instance <i>before</i> any bean * initialization callbacks (like InitializingBean's {@code afterPropertiesSet} * or a custom init-method). The bean will already be populated with property values. * The returned bean instance may be a wrapper around the original. * @param bean the new bean instance * @param beanName the name of the bean * @return the bean instance to use, either the original or a wrapped one; * if {@code null}, no subsequent BeanPostProcessors will be invoked * @throws org.springframework.beans.BeansException in case of errors * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet */ Object postProcessBeforeInitialization(Object bean, String beanName)throws BeansException;
/** * Apply this BeanPostProcessor to the given new bean instance <i>after</i> any bean * initialization callbacks (like InitializingBean's {@code afterPropertiesSet} * or a custom init-method). The bean will already be populated with property values. * The returned bean instance may be a wrapper around the original. * <p>In case of a FactoryBean, this callback will be invoked for both the FactoryBean * instance and the objects created by the FactoryBean (as of Spring 2.0). The * post-processor can decide whether to apply to either the FactoryBean or created * objects or both through corresponding {@code bean instanceof FactoryBean} checks. * <p>This callback will also be invoked after a short-circuiting triggered by a * {@link InstantiationAwareBeanPostProcessor#postProcessBeforeInstantiation} method, * in contrast to all other BeanPostProcessor callbacks. * @param bean the new bean instance * @param beanName the name of the bean * @return the bean instance to use, either the original or a wrapped one; * if {@code null}, no subsequent BeanPostProcessors will be invoked * @throws org.springframework.beans.BeansException in case of errors * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet * @see org.springframework.beans.factory.FactoryBean */ Object postProcessAfterInitialization(Object bean, String beanName)throws BeansException;
}
Apply this BeanPostProcessor to the given new bean instance before any bean initialization callbacks.
Apply this BeanPostProcessor to the given new bean instance before any bean initialization callbacks (like InitializingBean’s {@code afterPropertiesSet} or a custom init-method)
// Create bean instance. if (mbd.isSingleton()) { sharedInstance = getSingleton(beanName, newObjectFactory<Object>() {// <========= @Override public Object getObject()throws BeansException { try { return createBean(beanName, mbd, args); } catch (BeansException ex) { // Explicitly remove instance from singleton cache: It might have been put there // eagerly by the creation process, to allow for circular reference resolution. // Also remove any beans that received a temporary reference to the bean. destroySingleton(beanName); throw ex; } } }); bean = getObjectForBeanInstance(sharedInstance, name, beanName, mbd); }
// Create bean instance. if (mbd.isSingleton()) { sharedInstance = getSingleton(beanName, newObjectFactory<Object>() { @Override public Object getObject()throws BeansException { try { return createBean(beanName, mbd, args);// <========= } catch (BeansException ex) { // Explicitly remove instance from singleton cache: It might have been put there // eagerly by the creation process, to allow for circular reference resolution. // Also remove any beans that received a temporary reference to the bean. destroySingleton(beanName); throw ex; } } });
调用createBean创建对象
1 2 3 4
ObjectbeanInstance= doCreateBean(beanName, mbdToUse, args);// <========= if (logger.isDebugEnabled()) { logger.debug("Finished creating instance of bean '" + beanName + "'"); }
/** * Initialize the given bean instance, applying factory callbacks * as well as init methods and bean post processors. * <p>Called from {@link #createBean} for traditionally defined beans, * and from {@link #initializeBean} for existing bean instances. * @param beanName the bean name in the factory (for debugging purposes) * @param bean the new bean instance we may need to initialize * @param mbd the bean definition that the bean was created with * (can also be {@code null}, if given an existing bean instance) * @return the initialized bean instance (potentially wrapped) * @see BeanNameAware * @see BeanClassLoaderAware * @see BeanFactoryAware * @see #applyBeanPostProcessorsBeforeInitialization * @see #invokeInitMethods * @see #applyBeanPostProcessorsAfterInitialization */ protected Object initializeBean(final String beanName, final Object bean, RootBeanDefinition mbd) { if (System.getSecurityManager() != null) { AccessController.doPrivileged(newPrivilegedAction<Object>() { @Override public Object run() { invokeAwareMethods(beanName, bean); returnnull; } }, getAccessControlContext()); } else { invokeAwareMethods(beanName, bean); }
/** * Create a new ApplicationContextAwareProcessor for the given context. */ publicApplicationContextAwareProcessor(ConfigurableApplicationContext applicationContext) { this.applicationContext = applicationContext; this.embeddedValueResolver = newEmbeddedValueResolver(applicationContext.getBeanFactory()); }
/** * Annotation at the field or method/constructor parameter level * that indicates a default value expression for the affected argument. * * <p>Typically used for expression-driven dependency injection. Also supported * for dynamic resolution of handler method parameters, e.g. in Spring MVC. * * <p>A common use case is to assign default field values using * "#{systemProperties.myProp}" style expressions. * * <p>Note that actual processing of the {@code@Value} annotation is performed * by a {@link org.springframework.beans.factory.config.BeanPostProcessor * BeanPostProcessor} which in turn means that you <em>cannot</em> use * {@code@Value} within * {@link org.springframework.beans.factory.config.BeanPostProcessor * BeanPostProcessor} or * {@link org.springframework.beans.factory.config.BeanFactoryPostProcessor BeanFactoryPostProcessor} * types. Please consult the javadoc for the {@link AutowiredAnnotationBeanPostProcessor} * class (which, by default, checks for the presence of this annotation). * * @author Juergen Hoeller * @since 3.0 * @see AutowiredAnnotationBeanPostProcessor * @see Autowired * @see org.springframework.beans.factory.config.BeanExpressionResolver * @see org.springframework.beans.factory.support.AutowireCandidateResolver#getSuggestedValue */ @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented public@interface Value {
/** * The actual value expression: e.g. "#{systemProperties.myProp}". */ String value();
/** * Annotation providing a convenient and declarative mechanism for adding a * {@link org.springframework.core.env.PropertySource PropertySource} to Spring's * {@link org.springframework.core.env.Environment Environment}. To be used in * conjunction with @{@link Configuration} classes. * * <h3>Example usage</h3> * * <p>Given a file {@code app.properties} containing the key/value pair * {@code testbean.name=myTestBean}, the following {@code@Configuration} class * uses {@code@PropertySource} to contribute {@code app.properties} to the * {@code Environment}'s set of {@code PropertySources}. * * <pre class="code"> * @Configuration * @PropertySource("classpath:/com/myco/app.properties") * public class AppConfig { * @Autowired * Environment env; * * @Bean * public TestBean testBean() { * TestBean testBean = new TestBean(); * testBean.setName(env.getProperty("testbean.name")); * return testBean; * } * }</pre> * * Notice that the {@code Environment} object is @{@link * org.springframework.beans.factory.annotation.Autowired Autowired} into the * configuration class and then used when populating the {@code TestBean} object. Given * the configuration above, a call to {@code testBean.getName()} will return "myTestBean". * * <h3>Resolving ${...} placeholders in {@code <bean>} and {@code@Value} annotations</h3> * * In order to resolve ${...} placeholders in {@code <bean>} definitions or {@code@Value} * annotations using properties from a {@code PropertySource}, one must register * a {@code PropertySourcesPlaceholderConfigurer}. This happens automatically when using * {@code <context:property-placeholder>} in XML, but must be explicitly registered using * a {@code static} {@code@Bean} method when using {@code@Configuration} classes. See * the "Working with externalized values" section of @{@link Configuration}'s javadoc and * "a note on BeanFactoryPostProcessor-returning @Bean methods" of @{@link Bean}'s javadoc * for details and examples. * * <h3>Resolving ${...} placeholders within {@code@PropertySource} resource locations</h3> * * Any ${...} placeholders present in a {@code@PropertySource} {@linkplain #value() * resource location} will be resolved against the set of property sources already * registered against the environment. For example: * * <pre class="code"> * @Configuration * @PropertySource("classpath:/com/${my.placeholder:default/path}/app.properties") * public class AppConfig { * @Autowired * Environment env; * * @Bean * public TestBean testBean() { * TestBean testBean = new TestBean(); * testBean.setName(env.getProperty("testbean.name")); * return testBean; * } * }</pre> * * Assuming that "my.placeholder" is present in one of the property sources already * registered, e.g. system properties or environment variables, the placeholder will * be resolved to the corresponding value. If not, then "default/path" will be used as a * default. Expressing a default value (delimited by colon ":") is optional. If no * default is specified and a property cannot be resolved, an {@code * IllegalArgumentException} will be thrown. * * <h3>A note on property overriding with @PropertySource</h3> * * In cases where a given property key exists in more than one {@code .properties} * file, the last {@code@PropertySource} annotation processed will 'win' and override. * * For example, given two properties files {@code a.properties} and * {@code b.properties}, consider the following two configuration classes * that reference them with {@code@PropertySource} annotations: * * <pre class="code"> * @Configuration * @PropertySource("classpath:/com/myco/a.properties") * public class ConfigA { } * * @Configuration * @PropertySource("classpath:/com/myco/b.properties") * public class ConfigB { } * </pre> * * The override ordering depends on the order in which these classes are registered * with the application context. * <pre class="code"> * AnnotationConfigApplicationContext ctx = * new AnnotationConfigApplicationContext(); * ctx.register(ConfigA.class); * ctx.register(ConfigB.class); * ctx.refresh(); * </pre> * * In the scenario above, the properties in {@code b.properties} will override any * duplicates that exist in {@code a.properties}, because {@code ConfigB} was registered * last. * * <p>In certain situations, it may not be possible or practical to tightly control * property source ordering when using {@code@ProperySource} annotations. For example, * if the {@code@Configuration} classes above were registered via component-scanning, * the ordering is difficult to predict. In such cases - and if overriding is important - * it is recommended that the user fall back to using the programmatic PropertySource API. * See {@link org.springframework.core.env.ConfigurableEnvironment ConfigurableEnvironment} * and {@link org.springframework.core.env.MutablePropertySources MutablePropertySources} * javadocs for details. * * @author Chris Beams * @author Juergen Hoeller * @author Phillip Webb * @since 3.1 * @see PropertySources * @see Configuration * @see org.springframework.core.env.PropertySource * @see org.springframework.core.env.ConfigurableEnvironment#getPropertySources() * @see org.springframework.core.env.MutablePropertySources */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Repeatable(PropertySources.class) public@interface PropertySource {
/** * Indicate the name of this property source. If omitted, a name will * be generated based on the description of the underlying resource. * @see org.springframework.core.env.PropertySource#getName() * @see org.springframework.core.io.Resource#getDescription() */ String name()default"";
/** * Indicate the resource location(s) of the properties file to be loaded. * For example, {@code "classpath:/com/myco/app.properties"} or * {@code "file:/path/to/file"}. * <p>Resource location wildcards (e.g. **/*.properties) are not permitted; * each location must evaluate to exactly one {@code .properties} resource. * <p>${...} placeholders will be resolved against any/all property sources already * registered with the {@code Environment}. See {@linkplain PropertySource above} * for examples. * <p>Each location will be added to the enclosing {@code Environment} as its own * property source, and in the order declared. */ String[] value();
/** * Indicate if failure to find the a {@link #value() property resource} should be * ignored. * <p>{@code true} is appropriate if the properties file is completely optional. * Default is {@code false}. * @since 4.0 */ booleanignoreResourceNotFound()defaultfalse;
/** * A specific character encoding for the given resources, e.g. "UTF-8". * @since 4.3 */ String encoding()default"";
/** * Specify a custom {@link PropertySourceFactory}, if any. * <p>By default, a default factory for standard resource files will be used. * @since 4.3 * @see org.springframework.core.io.support.DefaultPropertySourceFactory * @see org.springframework.core.io.support.ResourcePropertySource */ Class<? extendsPropertySourceFactory> factory() default PropertySourceFactory.class;
}
显然该注解作用的对象是类,保留到运行时
再看参数:
String[] value()
Indicate the resource location(s) of the properties file to be loaded.
/** * Marker superinterface indicating that a bean is eligible to be * notified by the Spring container of a particular framework object * through a callback-style method. Actual method signature is * determined by individual subinterfaces, but should typically * consist of just one void-returning method that accepts a single * argument. * * <p>Note that merely implementing {@link Aware} provides no default * functionality. Rather, processing must be done explicitly, for example * in a {@link org.springframework.beans.factory.config.BeanPostProcessor BeanPostProcessor}. * Refer to {@link org.springframework.context.support.ApplicationContextAwareProcessor} * and {@link org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory} * for examples of processing {@code *Aware} interface callbacks. * * @author Chris Beams * @since 3.1 */ publicinterfaceAware {
}
Marker superinterface indicating that a bean is eligible to be notified by the Spring container of a particular framework object through a callback-style method.
/** * Indicate whether subclass-based (CGLIB) proxies are to be created as opposed * to standard Java interface-based proxies. The default is {@code false}. */ booleanproxyTargetClass()defaultfalse;
/** * Indicate that the proxy should be exposed by the AOP framework as a {@code ThreadLocal} * for retrieval via the {@link org.springframework.aop.framework.AopContext} class. * Off by default, i.e. no guarantees that {@code AopContext} access will work. * @since 4.3.1 */ booleanexposeProxy()defaultfalse;
/** * Registers an {@link org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator * AnnotationAwareAspectJAutoProxyCreator} against the current {@link BeanDefinitionRegistry} * as appropriate based on a given @{@link EnableAspectJAutoProxy} annotation. * * @author Chris Beams * @author Juergen Hoeller * @since 3.1 * @see EnableAspectJAutoProxy */ classAspectJAutoProxyRegistrarimplementsImportBeanDefinitionRegistrar {
/** * Register, escalate, and configure the AspectJ auto proxy creator based on the value * of the @{@link EnableAspectJAutoProxy#proxyTargetClass()} attribute on the importing * {@code@Configuration} class. */ @Override publicvoidregisterBeanDefinitions( AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {