SpringBoot注解分析

SpringBoot注解分析

常用注解

@Component

放在类上,把普通类实例化到spring容器中。大多数注解都基于这个注解

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Indexed
public @interface Component {

	/**
	 * The value may indicate a suggestion for a logical component name,
	 * to be turned into a Spring bean in case of an autodetected component.
	 * @return the suggested component name, if any (or empty String otherwise)
	 * *该值可能表示逻辑组件名称的建议,
	   *在自动检测到组件的情况下转换为springbean。
	   *@返回建议的组件名称(如果有)(否则返回空字符串)
	 */
	String value() default "";

}

@Bean

放在方法上,用@Bean标注方法等价于XML中配置bean,这个方法一般返回一个实体对象,告诉spring这里产生一个对象,然后这个对象会交给Spring管理。产生这个对象的方法Spring只会调用一次,随后这个Spring将会将这个Bean对象放在自己的容器中。

@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Bean {

	/**
	 * Alias for {@link #name}.
	 * <p>Intended to be used when no other attributes are needed, for example:
	 * {@code @Bean("customBeanName")}.
	 * @since 4.3.3
	 * @see #name
	 *{@link\name}的别名。
	 *<p>在不需要其他属性时使用,例如:
	 *{@code@Bean(“customBeanName”)}。
	 *@从4.3.3开始
	 *@见姓名
	 */

	@AliasFor("name")
	String[] value() default {};

	/**
	 * The name of this bean, or if several names, a primary bean name plus aliases.
	 * <p>If left unspecified, the name of the bean is the name of the annotated method.
	 * If specified, the method name is ignored.
	 * <p>The bean name and aliases may also be configured via the {@link #value}
	 * attribute if no other attributes are declared.
	 * @see #value
	 *这个bean的名称,或者如果是多个名称,则是一个主bean名称加上别名。
	 *<p>如果未指定,bean的名称就是带注释的方法的名称。
	 *如果指定,则忽略方法名。
	 *<p>bean名称和别名也可以通过{@link#value}配置
	 *属性,如果没有声明其他属性。
	 *@见#值
	 */
	@AliasFor("value")
	String[] name() default {};

	/**
	 * Are dependencies to be injected via convention-based autowiring by name or type?
	 * <p>Note that this autowire mode is just about externally driven autowiring based
	 * on bean property setter methods by convention, analogous to XML bean definitions.
	 * <p>The default mode does allow for annotation-driven autowiring. "no" refers to
	 * externally driven autowiring only, not affecting any autowiring demands that the
	 * bean class itself expresses through annotations.
	 * @see Autowire#BY_NAME
	 * @see Autowire#BY_TYPE
	 * @deprecated as of 5.1, since {@code @Bean} factory method argument resolution and
	 * {@code @Autowired} processing supersede name/type-based bean property injection
	 *依赖项是否通过基于约定的自动连线按名称或类型注入?
	 *<p>请注意,此自动布线模式只是基于外部驱动的自动布线
	 *在bean属性设置器方法上,类似于xmlbean定义。
	 *<p>默认模式允许注释驱动的自动连接。”否”指
	 *仅外部驱动自动布线,不影响任何自动布线要求
	 *bean类本身通过注释来表达。
	 *@按姓名查看自动连线
	 *@按类型查看Autowire
	 *由于{@code@Bean}工厂方法参数解析和
	 *{@code@Autowired}处理取代基于名称/类型的bean属性注入
	 */
	@Deprecated
	Autowire autowire() default Autowire.NO;

	/**
	 * Is this bean a candidate for getting autowired into some other bean?
	 * <p>Default is {@code true}; set this to {@code false} for internal delegates
	 * that are not meant to get in the way of beans of the same type in other places.
	 * @since 5.
	 *这个bean是否可以自动连接到其他bean中?
	 *<p>默认值是{@code true};对于内部委托,将此设置为{@code false}
	 *这并不意味着会妨碍其他地方相同类型的bean。
	 *@从5.1开始
	 */
	boolean autowireCandidate() default true;

	/**
	 * The optional name of a method to call on the bean instance during initialization.
	 * Not commonly used, given that the method may be called programmatically directly
	 * within the body of a Bean-annotated method.
	 * <p>The default value is {@code ""}, indicating no init method to be called.
	 * @see org.springframework.beans.factory.InitializingBean
	 * @see org.springframework.context.ConfigurableApplicationContext#refresh()
	 *在初始化期间调用bean实例的方法的可选名称。
	 *不常用,因为该方法可以通过编程方式直接调用
	 *在Bean注释的方法体中。
	 *<p>默认值是{@code“”},表示不调用init方法。
	 *@看到了吗org.springframework.beans.factory.InitializingBean
	 *@看到了吗org.springframework.context.ConfigurableApplicationContext#刷新()
	 */
	String initMethod() default "";

	/**
	 * The optional name of a method to call on the bean instance upon closing the
	 * application context, for example a {@code close()} method on a JDBC
	 * {@code DataSource} implementation, or a Hibernate {@code SessionFactory} object.
	 * The method must have no arguments but may throw any exception.
	 * <p>As a convenience to the user, the container will attempt to infer a destroy
	 * method against an object returned from the {@code @Bean} method. For example, given
	 * an {@code @Bean} method returning an Apache Commons DBCP {@code BasicDataSource},
	 * the container will notice the {@code close()} method available on that object and
	 * automatically register it as the {@code destroyMethod}. This 'destroy method
	 * inference' is currently limited to detecting only public, no-arg methods named
	 * 'close' or 'shutdown'. The method may be declared at any level of the inheritance
	 * hierarchy and will be detected regardless of the return type of the {@code @Bean}
	 * method (i.e., detection occurs reflectively against the bean instance itself at
	 * creation time).
	 * <p>To disable destroy method inference for a particular {@code @Bean}, specify an
	 * empty string as the value, e.g. {@code @Bean(destroyMethod="")}. Note that the
	 * {@link org.springframework.beans.factory.DisposableBean} callback interface will
	 * nevertheless get detected and the corresponding destroy method invoked: In other
	 * words, {@code destroyMethod=""} only affects custom close/shutdown methods and
	 * {@link java.io.Closeable}/{@link java.lang.AutoCloseable} declared close methods.
	 * <p>Note: Only invoked on beans whose lifecycle is under the full control of the
	 * factory, which is always the case for singletons but not guaranteed for any
	 * other scope.
	 * @see org.springframework.beans.factory.DisposableBean
	 * @see org.springframework.context.ConfigurableApplicationContext#close()
	 *关闭时调用bean实例的方法的可选名称
	 *应用程序上下文,例如JDBC上的{@code close()}方法
	 *{@code DataSource}实现,或Hibernate{@code SessionFactory}对象。
	 *方法必须没有参数,但可能引发任何异常。
	 *<p>为了方便用户,容器将尝试推断销毁
	 *方法对从{@code@Bean}方法返回的对象。例如,给定
	 *返回apachecommons DBCP{@code BasicDataSource}的{@code@Bean}方法,
	 *容器将注意到该对象上可用的{@code close()}方法,并且
	 *自动将其注册为{@code destroyMethod}。这种“毁灭”方法
	 *“推断”当前仅限于检测名为的公共方法,而不是参数方法
	 *“关闭”或“关闭”。方法可以在继承的任何级别上声明
	 *无论{@code@Bean}的返回类型如何,都将检测到
	 *方法(即,对位于
	 *创建时间)。
	 *<p>要禁用特定{@code@Bean}的销毁方法推理,请指定一个
	 *空字符串作为值,例如{@code@Bean(destroyMethod=“”)}。注意
	 *{@链接org.springframework.beans.工厂.DisposableBean}回调接口将
	 *然而,被检测到并调用相应的destroy方法:在其他
	 *{@code destroyMethod=“”}只影响自定义关闭/关闭方法和
	 *{@链接java.io.可关闭}/{@链接java.lang.AutoCloseable(自动关闭)}声明的close方法。
	 *<p>注意:仅在生命周期由
	 *工厂,这通常是单例,但不保证任何
	 *其他范围。
	 *@看到了吗org.springframework.beans.工厂.DisposableBean
	 *@看到了吗org.springframework.context.ConfigurableApplicationContext#关闭()
	 */
	String destroyMethod() default AbstractBeanDefinition.INFER_METHOD;

}

@Scope

注解在类上,描述spring容器如何创建Bean实例。

  • singleton: 表示在spring容器中的单例,通过spring容器获得该bean时总是返回唯一的实例
  • prototype:表示每次获得bean都会生成一个新的对象
  • request:表示在一次http请求内有效(只适用于web应用)
  • session:表示在一个用户会话内有效(只适用于web应用)
  • globalSession:表示在全局会话内有效(只适用于web应用)

在多数情况,我们只会使用singleton和prototype两种scope,如果未指定scope属性,默认为singleton

@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Scope {

	/**
	 * Alias for {@link #scopeName}.
	 * @see #scopeName
	 *{@link#scopeName}的别名。
	 *@请参见#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
	 *指定要用于带注释的组件/bean的作用域的名称。
	 *<p>默认为空字符串({@code“”}),这意味着
	 *{@link ConfigurableBeanFactory#SCOPE_SINGLETON SCOPE_SINGLETON}。
	 *@从4.2开始
	 *@请参阅ConfigurableBeanFactory#范围#原型
	 *@请参阅ConfigurableBeanFactory#SCOPE_SINGLETON
	 *@看到了吗org.springframework.web.context.WebApplicationContext#作用域请求
	 *@看到了吗org.springframework.web.应用上下文
	 *@见#值
	 */
	@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
	 *指定组件是否应配置为作用域代理
	 *如果是这样,代理应该是基于接口还是基于子类。
	 *<p>默认为{@link scopedProxy模式#DEFAULT},这通常表示
	 *除非有不同的默认值,否则不应创建作用域代理
	 *已在组件扫描指令级别配置。
	 *<p>类似于{@代码<作用域代理/>}支持springxml。
	 *@请参阅scopedProxy模式
	 */
	ScopedProxyMode proxyMode() default ScopedProxyMode.DEFAULT;

}

@Configuration

标注当前类是配置类,并会将当前类内声明的一个或多个以@Bean注解标记的方法的实例纳入到srping容器中,并且实例名就是方法名。(其实就是靠@Component注解)

/*
 * Copyright 2002-2020 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
 *
 *      https://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;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.annotation.AliasFor;
import org.springframework.stereotype.Component;


@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Configuration {

	/**
	 * Explicitly specify the name of the Spring bean definition associated with the
	 * {@code @Configuration} class. If left unspecified (the common case), a bean
	 * name will be automatically generated.
	 * <p>The custom name applies only if the {@code @Configuration} class is picked
	 * up via component scanning or supplied directly to an
	 * {@link AnnotationConfigApplicationContext}. If the {@code @Configuration} class
	 * is registered as a traditional XML bean definition, the name/id of the bean
	 * element will take precedence.
	 * @return the explicit component name, if any (or empty String otherwise)
	 * @see AnnotationBeanNameGenerator
	 *显式地指定与
	 *{@code@Configuration}类。如果未指定(常见情况),则为bean
	 *名称将自动生成。
	 *<p>自定义名称仅适用于{@code@Configuration}类
	 *通过组件扫描或直接提供给
	 *{@link AnnotationConfigApplicationContext}。如果{@code@Configuration}类
	 *注册为传统的xmlbean定义,即bean的名称/id
	 *元素将优先。
	 *@返回显式组件名,如果有(否则返回空字符串)
	 *@请参阅AnnotationBeanNameGenerator
	 */
	@AliasFor(annotation = Component.class)
	String value() default "";

	/**
	 * Specify whether {@code @Bean} methods should get proxied in order to enforce
	 * bean lifecycle behavior, e.g. to return shared singleton bean instances even
	 * in case of direct {@code @Bean} method calls in user code. This feature
	 * requires method interception, implemented through a runtime-generated CGLIB
	 * subclass which comes with limitations such as the configuration class and
	 * its methods not being allowed to declare {@code final}.
	 * <p>The default is {@code true}, allowing for 'inter-bean references' via direct
	 * method calls within the configuration class as well as for external calls to
	 * this configuration's {@code @Bean} methods, e.g. from another configuration class.
	 * If this is not needed since each of this particular configuration's {@code @Bean}
	 * methods is self-contained and designed as a plain factory method for container use,
	 * switch this flag to {@code false} in order to avoid CGLIB subclass processing.
	 * <p>Turning off bean method interception effectively processes {@code @Bean}
	 * methods individually like when declared on non-{@code @Configuration} classes,
	 * a.k.a. "@Bean Lite Mode" (see {@link Bean @Bean's javadoc}). It is therefore
	 * behaviorally equivalent to removing the {@code @Configuration} stereotype.
	 * @since 5.2
	 *指定{@code@Bean}方法是否应该被代理以便强制执行
	 *bean生命周期行为,例如返回共享的单例bean实例
	 *如果在用户代码中直接调用{@code@Bean}方法。此功能
	 *需要方法拦截,通过运行时生成的CGLIB实现
	 *子类,它具有诸如配置类和
	 *它的方法不允许声明{@code final}。
	 *<p>默认值是{@code true},允许通过direct进行“bean间引用”
	 *方法调用以及外部调用
	 *这个配置的{@code@Bean}方法,例如来自另一个配置类。
	 *如果由于每个特定配置的{@code@Bean}而不需要这样做
	 *方法是独立的,设计为容器使用的普通工厂方法,
	 *将此标志切换为{@code false},以避免处理CGLIB子类。
	 *<p>关闭bean方法拦截可以有效地处理{@code@bean}
	 *方法单独声明,比如在非{@code@Configuration}类上声明时,
	 *又称“@BeanLite模式”(参见{@linkbean@Bean的javadoc})。因此是的
	 *行为上等同于移除{@code@Configuration}原型。
	 *@从5.2开始

	 */
	boolean proxyBeanMethods() default true;

}

@ConfigurationProperties

将配置文件中的参数映射成一个对象,通过prefix来设定前缀,然后将后面的和对象的属性名一致就能实现注入(当然这个对象需要注入的属性需要提供get和set方法 - - - 因为spring底层其实就是通过反射调用该对象的set方法)

@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface ConfigurationProperties {

	/**
	 * The prefix of the properties that are valid to bind to this object. Synonym for
	 * {@link #prefix()}. A valid prefix is defined by one or more words separated with
	 * dots (e.g. {@code "acme.system.feature"}).
	 * @return the prefix of the properties to bind
	 *可绑定到此对象的有效属性的前缀。同义词
	 *{@link#prefix()}。有效前缀由一个或多个用分隔的单词定义
	 *点(例如{@code“顶点.system.feature"}).
	 *@返回要绑定的属性的前缀
	 */
	@AliasFor("prefix")
	String value() default "";

	/**
	 * The prefix of the properties that are valid to bind to this object. Synonym for
	 * {@link #value()}. A valid prefix is defined by one or more words separated with
	 * dots (e.g. {@code "acme.system.feature"}).
	 * @return the prefix of the properties to bind
	 *可绑定到此对象的有效属性的前缀。同义词
	 *{@link#value()}。有效前缀由一个或多个用分隔的单词定义
	 *点(例如{@code“顶点.system.feature"}).
	 *@返回要绑定的属性的前缀
	 */
	@AliasFor("value")
	String prefix() default "";

	/**
	 * Flag to indicate that when binding to this object invalid fields should be ignored.
	 * Invalid means invalid according to the binder that is used, and usually this means
	 * fields of the wrong type (or that cannot be coerced into the correct type).
	 * @return the flag value (default false)
	 *指示绑定到此对象时应忽略无效字段的标志。
	 *无效是指根据所使用的活页夹无效,通常这意味着
	 *类型错误的字段(或无法强制转换为正确类型的字段)。
	 *@返回标志值(默认为false)
	 */
	boolean ignoreInvalidFields() default false;

	/**
	 * Flag to indicate that when binding to this object unknown fields should be ignored.
	 * An unknown field could be a sign of a mistake in the Properties.
	 * @return the flag value (default true)
	 *指示绑定到此对象时应忽略未知字段的标志。
	 *未知字段可能表示属性中存在错误。
	 *@返回标志值(默认为true)
	 */
	boolean ignoreUnknownFields() default true;

}

@Value

value的作用其实和ConfigurationProperties作用差不多,就是读取配置文件中参数的值,但是value是放在变量上面的,且是单值读取,还有一点就是value标注的变量并不需要和配置文件的参数名字一致。

@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Value {

	/**
	 * The actual value expression &mdash; for example, <code>#{systemProperties.myProp}</code>.
	 * 实际值表达式&amp;mdash;例如,<code>#{系统属性.myProp}</code>。
	 */
	String value();

}

@Controller

用于标记在一个类上,使用它标记的类就是一个SpringMVC Controller 对象。

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Controller {

	/**
	 * The value may indicate a suggestion for a logical component name,
	 * to be turned into a Spring bean in case of an autodetected component.
	 * @return the suggested component name, if any (or empty String otherwise)
	 *该值可能表示逻辑组件名称的建议,
	 *在自动检测到组件的情况下转换为springbean。
	 *@返回建议的组件名称(如果有)(否则返回空字符串)
	 */
	@AliasFor(annotation = Component.class)
	String value() default "";

}

@Service

用于标记在一个类上,使用它标记的类就是一个SpringMVC Service 对象。

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Controller {

	/**
	 * The value may indicate a suggestion for a logical component name,
	 * to be turned into a Spring bean in case of an autodetected component.
	 * @return the suggested component name, if any (or empty String otherwise)
	 *该值可能表示逻辑组件名称的建议,
	 *在自动检测到组件的情况下转换为springbean。
	 *@返回建议的组件名称(如果有)(否则返回空字符串)
	 */
	@AliasFor(annotation = Component.class)
	String value() default "";

}

@Repository

用于标记在一个类上,使用它标记的类就是一个SpringMVC Repository对象。

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Controller {

	/**
	 * The value may indicate a suggestion for a logical component name,
	 * to be turned into a Spring bean in case of an autodetected component.
	 * @return the suggested component name, if any (or empty String otherwise)
	 *该值可能表示逻辑组件名称的建议,
	 *在自动检测到组件的情况下转换为springbean。
	 *@返回建议的组件名称(如果有)(否则返回空字符串)
	 */
	@AliasFor(annotation = Component.class)
	String value() default "";

}

@RestController

一个组合注解,写在类上面,是组合了@ResponseBody和@Controller,默认了类中所有的方法都包含ResponseBody注解的一种简写形式

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Controller
@ResponseBody
public @interface RestController {

	/**
	 * The value may indicate a suggestion for a logical component name,
	 * to be turned into a Spring bean in case of an autodetected component.
	 * @return the suggested component name, if any (or empty String otherwise)
	 * @since 4.0.1
	 *该值可能表示逻辑组件名称的建议,
	 *在自动检测到组件的情况下转换为springbean。
	 *@返回建议的组件名称(如果有)(否则返回空字符串)
	 *@从4.0.1开始
	 */
	@AliasFor(annotation = Controller.class)
	String value() default "";

}

@Resource

是按照名称来注入的,当找不到与名称匹配的bean才会按照类型来注入。其实我们平时用的@Resource都是用了他的默认的方式,即都不指定名字和类型。spring通过反射机制使用byName方法自动注入。

@Target({TYPE, FIELD, METHOD})
@Retention(RUNTIME)
public @interface Resource {
    /**
     * The JNDI name of the resource.  For field annotations,
     * the default is the field name.  For method annotations,
     * the default is the JavaBeans property name corresponding
     * to the method.  For class annotations, there is no default
     * and this must be specified.
     *资源的JNDI名称。对于字段注释,
	 *默认为字段名。对于方法注释,
	 *默认值是对应的JavaBeans属性名
	 *方法。对于类注释,没有默认值
	 *必须指定这一点。
     */
    String name() default "";

    /**
     * The name of the resource that the reference points to. It can
     * link to any compatible resource using the global JNDI names.
     *
     * @since Common Annotations 1.1
     *引用指向的资源的名称。它可以
	 *使用全局JNDI名称链接到任何兼容资源。
	 *
	 *@since Common Annotations 1.1版之后
     */

    String lookup() default "";

    /**
     * The Java type of the resource.  For field annotations,
     * the default is the type of the field.  For method annotations,
     * the default is the type of the JavaBeans property.
     * For class annotations, there is no default and this must be
     * specified.
     *资源的Java类型。对于字段注释,
	 *默认为字段的类型。对于方法注释,
	 *默认值是JavaBeans属性的类型。
	 *对于类注释,没有默认值,这必须是
	 *指定的。
     */
    Class<?> type() default java.lang.Object.class;

    /**
     * The two possible authentication types for a resource.
     */
    enum AuthenticationType {
            CONTAINER,
            APPLICATION
    }

    /**
     * The authentication type to use for this resource.
     * This may be specified for resources representing a
     * connection factory of any supported type, and must
     * not be specified for resources of other types.
     *用于此资源的身份验证类型。
	 *可以为表示
	 *任何支持类型的连接工厂,并且必须
	 *不能为其他类型的资源指定。
     */
    AuthenticationType authenticationType() default AuthenticationType.CONTAINER;

    /**
     * Indicates whether this resource can be shared between
     * this component and other components.
     * This may be specified for resources representing a
     * connection factory of any supported type, and must
     * not be specified for resources of other types.
     *指示此资源是否可以在
	 *此组件和其他组件。
	 *可以为表示
	 *任何支持类型的连接工厂,并且必须
	 *不能为其他类型的资源指定。
     */
    boolean shareable() default true;

    /**
     * A product specific name that this resource should be mapped to.
     * The name of this resource, as defined by the <code>name</code>
     * element or defaulted, is a name that is local to the application
     * component using the resource.  (It's a name in the JNDI
     * <code>java:comp/env</code> namespace.)  Many application servers
     * provide a way to map these local names to names of resources
     * known to the application server.  This mapped name is often a
     * <i>global</i> JNDI name, but may be a name of any form. <p>
     *
     * Application servers are not required to support any particular
     * form or type of mapped name, nor the ability to use mapped names.
     * The mapped name is product-dependent and often installation-dependent.
     * No use of a mapped name is portable.
     *此资源应映射到的产品特定名称。
	 *此资源的名称,由<code>名称</code>定义
	 *元素或默认值,是应用程序的本地名称
	 *使用资源的组件。(这是JNDI中的一个名字
	 *<代码>java:组件/环境</code>命名空间)许多应用程序服务器
	 *提供一种将这些本地名称映射到资源名称的方法
	 *应用程序服务器已知。此映射名称通常是
	 *<i>全局</i>JNDI名称,但可以是任何形式的名称。<p>在
	 *
	 *应用服务器不需要支持任何特定的
	 *映射名称的形式或类型,也不能使用映射名称。
	 *映射的名称取决于产品,通常取决于安装。
	 *映射名称的使用是不可移植的。
     */
    String mappedName() default "";

    /**
     * Description of this resource.  The description is expected
     * to be in the default language of the system on which the
     * application is deployed.  The description can be presented
     * to the Deployer to help in choosing the correct resource.
     *此资源的说明。需要说明
	 *使用系统的默认语言
	 *应用程序已部署。描述可以呈现
	 *以帮助部署人员选择正确的资源。
     */
    String description() default "";
}

@Resource 的装配顺序:

  1. 如果同时指定了 name 属性和 type 属性,那么 Spring 将从容器中找唯一匹配的 bean 进行装配,找不到则抛出异常
  2. 如果指定了 name 属性值,则从容器中查找名称匹配的 bean 进行装配,找不到则抛出异常
  3. 如果指定了 type 属性值,则从容器中查找类型匹配的唯一的 bean 进行装配,找不到或者找到多个都会抛出异常
  4. 如果都不指定,则会自动按照 byName 方式进行装配(我们一般都用的是这个。。。)

@Autowried

默认是按照类型进行装配注入,如果允许 null 值,可以设置它 required 为false。即:当不能确定 Spring 容器中一定拥有某个类的 Bean 时,可以在需要自动注入该类 Bean 的地方可以使用 @Autowired(required = false) ,这等于告诉 Spring:在找不到匹配 Bean 时也不报错。

@Target({ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Autowired {

	/**
	 * Declares whether the annotated dependency is required.
	 * <p>Defaults to {@code true}.
	 *声明是否需要带注释的依赖项。
	 *<p>默认为{@code true}。
	 */
	boolean required() default true;

}

@Qualifier

@Autowired是根据类型进行自动装配的。如果当spring上下文中存在不止一个A类型的bean时,就会抛出BeanCreationException异常;如果Spring上下文中不存在A类型的bean,而且我们又使用A类型,也会抛出BeanCreationException异常。针对存在多个A类型的Bean,我们可以联合使用@Qualifier和@Autowired来解决这些问题。

@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface Qualifier {

	String value() default "";

}

@SpringBootConfiguration

说明这是一个配置文件类,就像xml配置文件,而现在是用java配置文件。并会将当前类内声明的一个或多个以@Bean注解标记的方法的实例纳入到spring容器中,并且实例名就是方法名。

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Configuration
public @interface SpringBootConfiguration {

	/**
	 * Specify whether {@link Bean @Bean} methods should get proxied in order to enforce
	 * bean lifecycle behavior, e.g. to return shared singleton bean instances even in
	 * case of direct {@code @Bean} method calls in user code. This feature requires
	 * method interception, implemented through a runtime-generated CGLIB subclass which
	 * comes with limitations such as the configuration class and its methods not being
	 * allowed to declare {@code final}.
	 * <p>
	 * The default is {@code true}, allowing for 'inter-bean references' within the
	 * configuration class as well as for external calls to this configuration's
	 * {@code @Bean} methods, e.g. from another configuration class. If this is not needed
	 * since each of this particular configuration's {@code @Bean} methods is
	 * self-contained and designed as a plain factory method for container use, switch
	 * this flag to {@code false} in order to avoid CGLIB subclass processing.
	 * <p>
	 * Turning off bean method interception effectively processes {@code @Bean} methods
	 * individually like when declared on non-{@code @Configuration} classes, a.k.a.
	 * "@Bean Lite Mode" (see {@link Bean @Bean's javadoc}). It is therefore behaviorally
	 * equivalent to removing the {@code @Configuration} stereotype.
	 * @return whether to proxy {@code @Bean} methods
	 * @since 2.2
	 *指定{@linkbean@Bean}方法是否应该被代理以便强制执行
	 *bean生命周期行为,例如,即使在
	 *用户代码中直接调用{@code@Bean}方法的情况。此功能需要
	 *方法拦截,通过运行时生成的CGLIB子类实现
	 *会带来一些限制,比如配置类及其方法
	 *允许声明{@code final}。
	 *<p>
	 *默认值是{@codetrue},允许在
	 *配置类以及对此配置的外部调用
	 *{@code@Bean}方法,例如来自另一个配置类。如果不需要的话
	 *因为每个特定配置的{@code@Bean}方法都是
	 *独立的,设计成一种简单的工厂方法,用于集装箱、开关
	 *将此标志设置为{@code false},以避免处理CGLIB子类。
	 *<p>
	 *关闭bean方法拦截可以有效地处理{@code@bean}方法
	 *比如在非{@code@Configuration}类上声明时,也就是说。
	 *“@BeanLite模式”(参见{@linkbean@Bean的javadoc})。因此,行为是口头的
	 *相当于删除{@code@Configuration}原型。
	 *@return是否代理{@code@Bean}方法
	 *@从2.2开始
	 */
	@AliasFor(annotation = Configuration.class)
	boolean proxyBeanMethods() default true;

}

@EnableAutoConfiguration

表示开启自动配置,我们平时所说springboot无配置就是这个参数起的作用,他读取了springboot默认的配置。

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@AutoConfigurationPackage
@Import(AutoConfigurationImportSelector.class)
public @interface EnableAutoConfiguration {

	String ENABLED_OVERRIDE_PROPERTY = "spring.boot.enableautoconfiguration";

	/**
	 * Exclude specific auto-configuration classes such that they will never be applied.
	 * @return the classes to exclude
	 *排除特定的自动配置类,使其永远不会被应用。
	 *@返回要排除的类
	 */
	Class<?>[] exclude() default {};

	/**
	 * Exclude specific auto-configuration class names such that they will never be
	 * applied.
	 * @return the class names to exclude
	 * @since 1.3.0
	 *排除特定的自动配置类名,使它们永远不会
	 *应用。
	 *@返回要排除的类名
	 *@自1.3.0起
	 */
	String[] excludeName() default {};

}

@ComponentScan

表示自动扫描,这个扫描默认只能扫同一级的目录。

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Documented
@Repeatable(ComponentScans.class)
public @interface ComponentScan {

	/**
	 * Alias for {@link #basePackages}.
	 * <p>Allows for more concise annotation declarations if no other attributes
	 * are needed &mdash; for example, {@code @ComponentScan("org.my.pkg")}
	 * instead of {@code @ComponentScan(basePackages = "org.my.pkg")}.
	 *{@link#basePackages}的别名。
	 *<p>如果没有其他属性,则允许更简洁的注释声明
	 *例如,{@code@ComponentScan(“org.my.pkg.软件包")}
	 *而不是{@code@ComponentScan(basePackages=”org.my.pkg.软件包")}.
	 */
	@AliasFor("basePackages")
	String[] value() default {};

	/**
	 * Base packages to scan for annotated components.
	 * <p>{@link #value} is an alias for (and mutually exclusive with) this
	 * attribute.
	 * <p>Use {@link #basePackageClasses} for a type-safe alternative to
	 * String-based package names.
	 *扫描带注释组件的基本包。
	 *<p>{@link#value}是此的别名(与互斥)
	 *属性。
	 *<p>使用{@link#basePackageClasses}作为
	 *基于字符串的包名称。
	 */
	@AliasFor("value")
	String[] basePackages() default {};

	/**
	 * Type-safe alternative to {@link #basePackages} for specifying the packages
	 * to scan for annotated components. The package of each class specified will be scanned.
	 * <p>Consider creating a special no-op marker class or interface in each package
	 * that serves no purpose other than being referenced by this attribute.
	 *用于指定包的{@link#basePackages}的类型安全替代方法
 	 *扫描带注释的组件。将扫描指定的每个类的包。
	 *<p>考虑在每个包中创建一个特殊的no-op标记类或接口
	 *它除了被此属性引用之外没有其他用途。
	 */
	Class<?>[] basePackageClasses() default {};

	/**
	 * The {@link BeanNameGenerator} class to be used for naming detected components
	 * within the Spring container.
	 * <p>The default value of the {@link BeanNameGenerator} interface itself indicates
	 * that the scanner used to process this {@code @ComponentScan} annotation should
	 * use its inherited bean name generator, e.g. the default
	 * {@link AnnotationBeanNameGenerator} or any custom instance supplied to the
	 * application context at bootstrap time.
	 * @see AnnotationConfigApplicationContext#setBeanNameGenerator(BeanNameGenerator)
	 * @see AnnotationBeanNameGenerator
	 * @see FullyQualifiedAnnotationBeanNameGenerator
	 *用于命名检测到的组件的{@link BeanNameGenerator}类
	 *在弹簧容器内。
	 *<p>{@link beannamGenerator}接口本身的默认值表示
	 *用于处理此{@code@ComponentScan}注释的扫描仪应该
	 *使用它继承的bean名称生成器,例如默认的
	 *{@link AnnotationBeanNameGenerator}或提供给
	 *引导时的应用程序上下文。
	 *@请参阅AnnotationConfigApplicationContext\setBeanNameGenerator(BeanNameGenerator)
	 *@请参阅AnnotationBeanNameGenerator
	 *@查看完全合格的注释
	 */
	Class<? extends BeanNameGenerator> nameGenerator() default BeanNameGenerator.class;

	/**
	 * The {@link ScopeMetadataResolver} to be used for resolving the scope of detected components.
	 *用于解析检测到的组件范围的{@link ScopeMetadataResolver}。
	 */
	Class<? extends ScopeMetadataResolver> scopeResolver() default AnnotationScopeMetadataResolver.class;

	/**
	 * Indicates whether proxies should be generated for detected components, which may be
	 * necessary when using scopes in a proxy-style fashion.
	 * <p>The default is defer to the default behavior of the component scanner used to
	 * execute the actual scan.
	 * <p>Note that setting this attribute overrides any value set for {@link #scopeResolver}.
	 * @see ClassPathBeanDefinitionScanner#setScopedProxyMode(ScopedProxyMode)
	 *指示是否应为检测到的组件生成代理,这可能是
	 *以代理样式方式使用作用域时必需。
	 *<p>默认值是根据组件扫描程序的默认行为
	 *执行实际扫描。
	 *<p>请注意,设置此属性会覆盖为{@link#scopeResolver}设置的任何值。
	 *@see ClassPathBeanDefinitionScanner\setScopedProxyMode(ScopedProxyMode)
	 */
	ScopedProxyMode scopedProxy() default ScopedProxyMode.DEFAULT;

	/**
	 * Controls the class files eligible for component detection.
	 * <p>Consider use of {@link #includeFilters} and {@link #excludeFilters}
	 * for a more flexible approach.
	 *控制符合组件检测条件的类文件。
	 *<p>考虑使用{@link#includeFilters}和{@link\#excludeFilters}
	 *更灵活的方法。
	 */
	String resourcePattern() default ClassPathScanningCandidateComponentProvider.DEFAULT_RESOURCE_PATTERN;

	/**
	 * Indicates whether automatic detection of classes annotated with {@code @Component}
	 * {@code @Repository}, {@code @Service}, or {@code @Controller} should be enabled.
	 *指示是否自动检测用{@code@Component}注释的类
	 *应启用{@code@Repository}、{@code@Service}或{@code@Controller}。
	 */
	boolean useDefaultFilters() default true;

	/**
	 * Specifies which types are eligible for component scanning.
	 * <p>Further narrows the set of candidate components from everything in {@link #basePackages}
	 * to everything in the base packages that matches the given filter or filters.
	 * <p>Note that these filters will be applied in addition to the default filters, if specified.
	 * Any type under the specified base packages which matches a given filter will be included,
	 * even if it does not match the default filters (i.e. is not annotated with {@code @Component}).
	 * @see #resourcePattern()
	 * @see #useDefaultFilters()
	 *指定哪些类型有资格进行组件扫描。
	 *<p>进一步缩小{@link#basePackages}中的所有候选组件集
	 *与给定筛选器匹配的基包中的所有内容。
	 *<p>请注意,如果指定了这些过滤器,那么除了默认过滤器之外,还将应用这些过滤器。
	 *将包括指定基包下与给定筛选器匹配的任何类型,
	 *即使它与默认过滤器不匹配(即没有用{@code@Component}注释)。
	 *@请参阅资源模式()
	 *@请参见#useDefaultFilters()
	 */
	Filter[] includeFilters() default {};

	/**
	 * Specifies which types are not eligible for component scanning.
	 * @see #resourcePattern
	 *指定哪些类型不适合组件扫描。
	 *@see资源模式
	 */
	Filter[] excludeFilters() default {};

	/**
	 * Specify whether scanned beans should be registered for lazy initialization.
	 * <p>Default is {@code false}; switch this to {@code true} when desired.
	 * @since 4.1
	 *指定是否应为延迟初始化注册扫描的bean。
	 *<p>默认值是{@code false};如果需要,将其切换到{@code true}。
	 *@从4.1开始
	 */
	boolean lazyInit() default false;


	/**
	 * Declares the type filter to be used as an {@linkplain ComponentScan#includeFilters
	 * include filter} or {@linkplain ComponentScan#excludeFilters exclude filter}.
	 *声明要用作{@linkplain ComponentScan\includeFilter的类型筛选器
	 *include filter}或{@linkplain ComponentScan#excludeFilters排除筛选器}。
	 */
	@Retention(RetentionPolicy.RUNTIME)
	@Target({})
	@interface Filter {

		/**
		 * The type of filter to use.
		 * <p>Default is {@link FilterType#ANNOTATION}.
		 * @see #classes
		 * @see #pattern
		 *要使用的筛选器类型。
		 *<p>默认值是{@link FilterType\#ANNOTATION}。
		 *@查看课程
		 *@见#图案
		 */
		FilterType type() default FilterType.ANNOTATION;

		/**
		 * Alias for {@link #classes}.
		 * @see #classes
		 *{@link#classes}的别名。
		 *@查看课程
		 */
		@AliasFor("classes")
		Class<?>[] value() default {};

		/**
		 * The class or classes to use as the filter.
		 * <p>The following table explains how the classes will be interpreted
		 * based on the configured value of the {@link #type} attribute.
		 * <table border="1">
		 * <tr><th>{@code FilterType}</th><th>Class Interpreted As</th></tr>
		 * <tr><td>{@link FilterType#ANNOTATION ANNOTATION}</td>
		 * <td>the annotation itself</td></tr>
		 * <tr><td>{@link FilterType#ASSIGNABLE_TYPE ASSIGNABLE_TYPE}</td>
		 * <td>the type that detected components should be assignable to</td></tr>
		 * <tr><td>{@link FilterType#CUSTOM CUSTOM}</td>
		 * <td>an implementation of {@link TypeFilter}</td></tr>
		 * </table>
		 * <p>When multiple classes are specified, <em>OR</em> logic is applied
		 * &mdash; for example, "include types annotated with {@code @Foo} OR {@code @Bar}".
		 * <p>Custom {@link TypeFilter TypeFilters} may optionally implement any of the
		 * following {@link org.springframework.beans.factory.Aware Aware} interfaces, and
		 * their respective methods will be called prior to {@link TypeFilter#match match}:
		 * <ul>
		 * <li>{@link org.springframework.context.EnvironmentAware EnvironmentAware}</li>
		 * <li>{@link org.springframework.beans.factory.BeanFactoryAware BeanFactoryAware}
		 * <li>{@link org.springframework.beans.factory.BeanClassLoaderAware BeanClassLoaderAware}
		 * <li>{@link org.springframework.context.ResourceLoaderAware ResourceLoaderAware}
		 * </ul>
		 * <p>Specifying zero classes is permitted but will have no effect on component
		 * scanning.
		 * @since 4.2
		 * @see #value
		 * @see #type
		 *用作筛选器的一个或多个类。
		 *<p>下表说明了如何解释类
		 *基于{@link#type}属性的配置值。
		 *<table border=“1”>
		 *<tr><th>{@code FilterType}</th><th>类解释为</th></tr>
		 *<tr><td>{@link FilterType注解注解}</td>
		 *<td>注释本身</td></tr>
		 *<tr><td>{@link FilterType可分配类型可分配类型</td>
		 *<td>检测到的组件应分配给的类型</td></tr>
		 *<tr><td>{@link FilterType#自定义}</td>
		 *{@link TypeFilter}的实现
		 *</table>
		 *<p>当指定多个类时,<em>或</em>逻辑被应用
		 *例如,“包括用{@code@Foo}或{@code@Bar}注释的类型”。
		 *<p>自定义{@link TypeFilter TypeFilters}可以选择实现
		 *跟随{@linkorg.springframework.beans.工厂。知道吗Aware}接口,以及
		 *它们各自的方法将在{@link TypeFilter#match match}之前调用:
		 *<ul>
		 *<li>{@链接org.springframework.context.EnvironmentAware EnvironmentAware}</li>
		 *<li>{@链接org.springframework.beans.factory.BeanFactoryAwareBeanFactoryAware}
		 *<li>{@链接org.springframework.beans.factory.BeanClassLoaderwareBeanClassLoaderware}
		 *<li>{@链接org.springframework.context.resourceLoaderware ResourceLoaderware}
		 *</ul>
		 *<p>允许指定零类,但不会对组件产生影响
		 *正在扫描。
		 *@从4.2开始
		 *@见#值
		 *@见#类型

		 */
		@AliasFor("value")
		Class<?>[] classes() default {};

		/**
		 * The pattern (or patterns) to use for the filter, as an alternative
		 * to specifying a Class {@link #value}.
		 * <p>If {@link #type} is set to {@link FilterType#ASPECTJ ASPECTJ},
		 * this is an AspectJ type pattern expression. If {@link #type} is
		 * set to {@link FilterType#REGEX REGEX}, this is a regex pattern
		 * for the fully-qualified class names to match.
		 * @see #type
		 * @see #classes
		 *作为替代方案,用于筛选器的一个或多个模式
		 *指定一个类{@link#value}。
		 *<p>如果{@link#type}设置为{@link FilterType#ASPECTJ ASPECTJ},
		 *这是一个AspectJ类型模式表达式。如果{@link#type}是
		 *设置为{@link FilterType#REGEX REGEX},这是一个REGEX模式
		 *以匹配完全限定类名。
		 *@见#类型
		 *@查看课程
		 */
		String[] pattern() default {};

	}

}

@SpringBootApplication

这个注解就是集成了:@SpringBootConfiguration、@EnableAutoConfiguration、@ComponentScan这三个注解。

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(excludeFilters = { @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
		@Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })
public @interface SpringBootApplication {

	/**
	 * Exclude specific auto-configuration classes such that they will never be applied.
	 * @return the classes to exclude
	 *排除特定的自动配置类,使其永远不会被应用。
	 *@返回要排除的类
	 */
	@AliasFor(annotation = EnableAutoConfiguration.class)
	Class<?>[] exclude() default {};

	/**
	 * Exclude specific auto-configuration class names such that they will never be
	 * applied.
	 * @return the class names to exclude
	 * @since 1.3.0
	 *排除特定的自动配置类名,使它们永远不会
	 *应用。
	 *@返回要排除的类名
	 *@自1.3.0起
	 */
	@AliasFor(annotation = EnableAutoConfiguration.class)
	String[] excludeName() default {};

	/**
	 * Base packages to scan for annotated components. Use {@link #scanBasePackageClasses}
	 * for a type-safe alternative to String-based package names.
	 * <p>
	 * <strong>Note:</strong> this setting is an alias for
	 * {@link ComponentScan @ComponentScan} only. It has no effect on {@code @Entity}
	 * scanning or Spring Data {@link Repository} scanning. For those you should add
	 * {@link org.springframework.boot.autoconfigure.domain.EntityScan @EntityScan} and
	 * {@code @Enable...Repositories} annotations.
	 * @return base packages to scan
	 * @since 1.3.0
	 *扫描带注释组件的基本包。使用{@link#scanBasePackageClasses}
	 *作为基于字符串的包名的类型安全替代项。
	 *<p>
	 *<strong>注意:</strong>此设置是的别名
	 *{@link ComponentScan@ComponentScan}仅限。它对{@code@Entity}没有影响
	 *扫描或Spring数据{@link Repository}扫描。对于那些你应该补充的
	 *{@链接org.springframework.boot.自动配置.domain.EntityScan@EntityScan}和
	 *{@code@Enable…Repositories}注释。
	 *@返回要扫描的基本包
	 *@自1.3.0起
	 */
	@AliasFor(annotation = ComponentScan.class, attribute = "basePackages")
	String[] scanBasePackages() default {};

	/**
	 * Type-safe alternative to {@link #scanBasePackages} for specifying the packages to
	 * scan for annotated components. The package of each class specified will be scanned.
	 * <p>
	 * Consider creating a special no-op marker class or interface in each package that
	 * serves no purpose other than being referenced by this attribute.
	 * <p>
	 * <strong>Note:</strong> this setting is an alias for
	 * {@link ComponentScan @ComponentScan} only. It has no effect on {@code @Entity}
	 * scanning or Spring Data {@link Repository} scanning. For those you should add
	 * {@link org.springframework.boot.autoconfigure.domain.EntityScan @EntityScan} and
	 * {@code @Enable...Repositories} annotations.
	 * @return base packages to scan
	 * @since 1.3.0
	 *键入{@link#scanBasePackages}的安全替代方法,用于将包指定给
	 *扫描带注释的组件。将扫描指定的每个类的包。
	 *<p>
	 *考虑在每个包中创建一个特殊的no-op标记类或接口
	 *除了被此属性引用外,没有其他用途。
	 *<p>
	 *<strong>注意:</strong>此设置是的别名
	 *{@link ComponentScan@ComponentScan}仅限。它对{@code@Entity}没有影响
	 *扫描或Spring数据{@link Repository}扫描。对于那些你应该补充的
	 *{@链接org.springframework.boot.自动配置.domain.EntityScan@EntityScan}和
	 *{@code@Enable…Repositories}注释。
	 *@返回要扫描的基本包
	 *@自1.3.0起
	 */
	@AliasFor(annotation = ComponentScan.class, attribute = "basePackageClasses")
	Class<?>[] scanBasePackageClasses() default {};

	/**
	 * The {@link BeanNameGenerator} class to be used for naming detected components
	 * within the Spring container.
	 * <p>
	 * The default value of the {@link BeanNameGenerator} interface itself indicates that
	 * the scanner used to process this {@code @SpringBootApplication} annotation should
	 * use its inherited bean name generator, e.g. the default
	 * {@link AnnotationBeanNameGenerator} or any custom instance supplied to the
	 * application context at bootstrap time.
	 * @return {@link BeanNameGenerator} to use
	 * @see SpringApplication#setBeanNameGenerator(BeanNameGenerator)
	 * @since 2.3.0
	 *用于命名检测到的组件的{@link BeanNameGenerator}类
	 *在弹簧容器内。
	 *<p>
	 *{@link beannamGenerator}接口本身的默认值表明
	 *用于处理{@code@SpringBootApplication}注释的扫描仪应该
	 *使用它继承的bean名称生成器,例如默认的
	 *{@link AnnotationBeanNameGenerator}或提供给
	 *引导时的应用程序上下文。
	 *@return{@link BeanNameGenerator}使用
	 *@see SpringApplication设置名称生成器(BeanNameGenerator)
	 *@从2.3.0开始
	 */
	@AliasFor(annotation = ComponentScan.class, attribute = "nameGenerator")
	Class<? extends BeanNameGenerator> nameGenerator() default BeanNameGenerator.class;

	/**
	 * Specify whether {@link Bean @Bean} methods should get proxied in order to enforce
	 * bean lifecycle behavior, e.g. to return shared singleton bean instances even in
	 * case of direct {@code @Bean} method calls in user code. This feature requires
	 * method interception, implemented through a runtime-generated CGLIB subclass which
	 * comes with limitations such as the configuration class and its methods not being
	 * allowed to declare {@code final}.
	 * <p>
	 * The default is {@code true}, allowing for 'inter-bean references' within the
	 * configuration class as well as for external calls to this configuration's
	 * {@code @Bean} methods, e.g. from another configuration class. If this is not needed
	 * since each of this particular configuration's {@code @Bean} methods is
	 * self-contained and designed as a plain factory method for container use, switch
	 * this flag to {@code false} in order to avoid CGLIB subclass processing.
	 * <p>
	 * Turning off bean method interception effectively processes {@code @Bean} methods
	 * individually like when declared on non-{@code @Configuration} classes, a.k.a.
	 * "@Bean Lite Mode" (see {@link Bean @Bean's javadoc}). It is therefore behaviorally
	 * equivalent to removing the {@code @Configuration} stereotype.
	 * @since 2.2
	 * @return whether to proxy {@code @Bean} methods
	 *指定{@linkbean@Bean}方法是否应该被代理以便强制执行
	 *bean生命周期行为,例如,即使在
	 *用户代码中直接调用{@code@Bean}方法的情况。此功能需要
	 *方法拦截,通过运行时生成的CGLIB子类实现
	 *会带来一些限制,比如配置类及其方法
	 *允许声明{@code final}。
	 *<p>
	 *默认值是{@codetrue},允许在
	 *配置类以及对此配置的外部调用
	 *{@code@Bean}方法,例如来自另一个配置类。如果不需要的话
	 *因为每个特定配置的{@code@Bean}方法都是
	 *独立的,设计成一种简单的工厂方法,用于集装箱、开关
	 *将此标志设置为{@code false},以避免处理CGLIB子类。
	 *<p>
	 *关闭bean方法拦截可以有效地处理{@code@bean}方法
	 *比如在非{@code@Configuration}类上声明时,也就是说。
	 *“@BeanLite模式”(参见{@linkbean@Bean的javadoc})。因此,行为是口头的
	 *相当于删除{@code@Configuration}原型。
	 *@从2.2开始
	 *@return是否代理{@code@Bean}方法
	 */
	@AliasFor(annotation = Configuration.class)
	boolean proxyBeanMethods() default true;

}

@EnableConfigurationProperties

将带有@ConfigurationProperties注解的类注入为Spring容器的Bean。如果使用了@ConfigurationProperties但是没有在启动类上增加这个注解,则@ConfigurationProperties将不起作用。

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Import(EnableConfigurationPropertiesRegistrar.class)
public @interface EnableConfigurationProperties {

	/**
	 * The bean name of the configuration properties validator.
	 * @since 2.2.0
	 *配置属性验证器的bean名称。
	 *@从2.2.0开始
	 */
	String VALIDATOR_BEAN_NAME = "configurationPropertiesValidator";

	/**
	 * Convenient way to quickly register
	 * {@link ConfigurationProperties @ConfigurationProperties} annotated beans with
	 * Spring. Standard Spring Beans will also be scanned regardless of this value.
	 * @return {@code @ConfigurationProperties} annotated beans to register
	 *快速注册的便捷方式
 	 *{@link ConfigurationProperties@ConfigurationProperties}带注释的bean
	 *春天。不管这个值是多少,标准的springbean也将被扫描。
	 *@return{@code@ConfigurationProperties}要注册的带注释bean
	 */
	Class<?>[] value() default {};

}

@Async

表示这个方法为异步方法,@Async就相当于另起一个线程。

@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Async {

	/**
	 * A qualifier value for the specified asynchronous operation(s).
	 * <p>May be used to determine the target executor to be used when executing
	 * the asynchronous operation(s), matching the qualifier value (or the bean
	 * name) of a specific {@link java.util.concurrent.Executor Executor} or
	 * {@link org.springframework.core.task.TaskExecutor TaskExecutor}
	 * bean definition.
	 * <p>When specified on a class-level {@code @Async} annotation, indicates that the
	 * given executor should be used for all methods within the class. Method-level use
	 * of {@code Async#value} always overrides any value set at the class level.
	 * @since 3.1.2
	 *指定的异步操作的限定符值。
	 *<p>可用于确定执行时要使用的目标执行器
	 *与限定符值(或bean)匹配的异步操作
	 *一个特定的{@link的名称)java.util.concurrent.Executor Executor}或
	 *{@链接org.springframework.core.任务.任务执行器任务执行者}
	 *bean定义。
	 *<p>在类级别{@code@Async}注释上指定时,表示
	 *给定的执行器应该用于类中的所有方法。方法级使用
	 *of{@code Async#value}始终重写类级别上设置的任何值。
	 *@从3.1.2开始
	 */
	String value() default "";

}

@EnableAsync

这个注解需要加在启动类上,表示支持异步操作;如果不加,则@Async将不起作用。

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Import(AsyncConfigurationSelector.class)
public @interface EnableAsync {

	/**
	 * Indicate the 'async' annotation type to be detected at either class
	 * or method level.
	 * <p>By default, both Spring's @{@link Async} annotation and the EJB 3.1
	 * {@code @javax.ejb.Asynchronous} annotation will be detected.
	 * <p>This attribute exists so that developers can provide their own
	 * custom annotation type to indicate that a method (or all methods of
	 * a given class) should be invoked asynchronously.
	 *指示要在任一类中检测的“async”批注类型
	 *或方法级别。
	 *<p>默认情况下,Spring的@{@link Async}注释和ejb3.1
	 *{@代码@javax.ejb.异步}将检测到批注。
	 *<p>此属性的存在使得开发人员可以提供自己的
	 *自定义批注类型,以指示方法(或
	 *应异步调用。
	 */
	Class<? extends Annotation> annotation() default Annotation.class;

	/**
	 * Indicate whether subclass-based (CGLIB) proxies are to be created as opposed
	 * to standard Java interface-based proxies.
	 * <p><strong>Applicable only if the {@link #mode} is set to {@link AdviceMode#PROXY}</strong>.
	 * <p>The default is {@code false}.
	 * <p>Note that setting this attribute to {@code true} will affect <em>all</em>
	 * Spring-managed beans requiring proxying, not just those marked with {@code @Async}.
	 * For example, other beans marked with Spring's {@code @Transactional} annotation
	 * will be upgraded to subclass proxying at the same time. This approach has no
	 * negative impact in practice unless one is explicitly expecting one type of proxy
	 * vs. another &mdash; for example, in tests.
	 *指示是否相反地创建基于子类(CGLIB)的代理
	 *到标准的基于Java接口的代理。
	 *<p><strong>仅当{@link#mode}设置为{@link AdviceMode}PROXY}时才适用。
	 *<p>默认值是{@code false}。
	 *<p>请注意,将此属性设置为{@code true}将影响<em>所有</em>
	 *需要代理的Spring托管bean,而不仅仅是那些用{@code@Async}标记的bean。
	 *例如,用Spring的{@code@Transactional}注释标记的其他bean
	 *将同时升级到子类代理。这种方法没有
	 *在实践中的负面影响,除非明确要求一种类型的代理
	 *例如,在测试中。
	 */
	boolean proxyTargetClass() default false;

	/**
	 * Indicate how async advice should be applied.
	 * <p><b>The default is {@link AdviceMode#PROXY}.</b>
	 * Please note that proxy mode allows for interception of calls through the proxy
	 * only. Local calls within the same class cannot get intercepted that way; an
	 * {@link Async} annotation on such a method within a local call will be ignored
	 * since Spring's interceptor does not even kick in for such a runtime scenario.
	 * For a more advanced mode of interception, consider switching this to
	 * {@link AdviceMode#ASPECTJ}.
	 *指示应如何应用异步建议。
	 *<p><b>默认值是{@link AdviceMode#PROXY}</b>
	 *请注意,代理模式允许通过代理拦截呼叫
	 *只有。同一个类中的本地调用不能以这种方式被截获;一个
	 *本地调用中此类方法的{@link Async}注释将被忽略
	 *因为Spring的拦截器甚至不会在这样的运行时场景中启动。
	 *对于更高级的拦截模式,请考虑将其切换到
	 *{@link AdviceMode\ASPECTJ}。
	 */
	AdviceMode mode() default AdviceMode.PROXY;

	/**
	 * Indicate the order in which the {@link AsyncAnnotationBeanPostProcessor}
	 * should be applied.
	 * <p>The default is {@link Ordered#LOWEST_PRECEDENCE} in order to run
	 * after all other post-processors, so that it can add an advisor to
	 * existing proxies rather than double-proxy.
	 *指示{@link AsyncAnnotationBeanPostProcessor}的顺序
	 *应该应用。
	 *<p>为了运行,默认值是{@link Ordered#最低优先级}
	 *在所有其他后处理程序之后,以便它可以向
	 *现有代理而不是双代理。
	 */
	int order() default Ordered.LOWEST_PRECEDENCE;

}

@Scheduled

定时任务。

@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Repeatable(Schedules.class)
public @interface Scheduled {

	/**
	 * A special cron expression value that indicates a disabled trigger: {@value}.
	 * <p>This is primarily meant for use with <code>${...}</code> placeholders,
	 * allowing for external disabling of corresponding scheduled methods.
	 * @since 5.1
	 * @see ScheduledTaskRegistrar#CRON_DISABLED
	 *一个特殊的cron表达式值,指示禁用的触发器:{@value}。
	 *<p>这主要用于<code>${…}</code>占位符,
	 *允许外部禁用相应的调度方法。
	 *@从5.1开始
	 *@see ScheduledTaskRegistrar\CRON#u禁用
	 */
	String CRON_DISABLED = ScheduledTaskRegistrar.CRON_DISABLED;


	/**
	 * A cron-like expression, extending the usual UN*X definition to include triggers
	 * on the second, minute, hour, day of month, month, and day of week.
	 * <p>For example, {@code "0 * * * * MON-FRI"} means once per minute on weekdays
	 * (at the top of the minute - the 0th second).
	 * <p>The fields read from left to right are interpreted as follows.
	 * <ul>
	 * <li>second</li>
	 * <li>minute</li>
	 * <li>hour</li>
	 * <li>day of month</li>
	 * <li>month</li>
	 * <li>day of week</li>
	 * </ul>
	 * <p>The special value {@link #CRON_DISABLED "-"} indicates a disabled cron
	 * trigger, primarily meant for externally specified values resolved by a
	 * <code>${...}</code> placeholder.
	 * @return an expression that can be parsed to a cron schedule
	 * @see org.springframework.scheduling.support.CronSequenceGenerator
	 *一个类似cron的表达式,扩展了通常的UN*X定义以包括触发器
	 *在秒、分、时、月、月、日。
	 *<p>例如,{@code“0****MON-FRI”}表示工作日每分钟一次
	 *(在分钟的顶部-第0秒)。
	 *<p>从左到右读取的字段解释如下。
	 *<ul>
	 *<li>秒</li>
	 *<li>分钟</li>
	 *<li>小时</li>
	 *<li>月日</li>
	 *<li>月</li>
	 *<li>星期几</li>
	 *</ul>
	 *<p>特殊值{@link#CRON#DISABLED“-”}表示禁用的CRON
	 *触发器,主要用于由
	 *<code>${…}</code>占位符。
	 *@返回一个可以解析为cron计划的表达式
	 *@看到了吗org.springframework.scheduling.support.CronSequenceGenerator
	 */
	String cron() default "";

	/**
	 * A time zone for which the cron expression will be resolved. By default, this
	 * attribute is the empty String (i.e. the server's local time zone will be used).
	 * @return a zone id accepted by {@link java.util.TimeZone#getTimeZone(String)},
	 * or an empty String to indicate the server's default time zone
	 * @since 4.0
	 * @see org.springframework.scheduling.support.CronTrigger#CronTrigger(String, java.util.TimeZone)
	 * @see java.util.TimeZone
	 *将为其解析cron表达式的时区。默认情况下
	 *属性是空字符串(即将使用服务器的本地时区)。
	 *@返回{@link接受的区域idjava.util.TimeZone#获取时区(字符串)},
	 *或空字符串来指示服务器的默认时区
	 *@从4.0开始
	 *@看到了吗org.springframework.scheduling.支持.CronTrigger\CronTrigger(字符串,java.util.TimeZone)
	 *@看到了吗java.util.TimeZone
	 */
	String zone() default "";

	/**
	 * Execute the annotated method with a fixed period in milliseconds between the
	 * end of the last invocation and the start of the next.
	 * @return the delay in milliseconds
	 *在
	 *上一次调用结束,下一次调用开始。
	 *@返回毫秒延迟
	 */
	long fixedDelay() default -1;

	/**
	 * Execute the annotated method with a fixed period in milliseconds between the
	 * end of the last invocation and the start of the next.
	 * @return the delay in milliseconds as a String value, e.g. a placeholder
	 * or a {@link java.time.Duration#parse java.time.Duration} compliant value
	 * @since 3.2.2
	 *在
	 *上一次调用结束,下一次调用开始。
	 *@将延迟以毫秒为单位返回字符串值,例如占位符
	 *或{@链接java.time.Duration解析java.time.Duration.持续时间}合规价值
	 *@从3.2.2开始
	 */
	String fixedDelayString() default "";

	/**
	 * Execute the annotated method with a fixed period in milliseconds between
	 * invocations.
	 * @return the period in milliseconds
	 *执行带注释的方法,其时间间隔为毫秒
	 *调用。
	 *@返回时间段(毫秒)
	 */
	long fixedRate() default -1;

	/**
	 * Execute the annotated method with a fixed period in milliseconds between
	 * invocations.
	 * @return the period in milliseconds as a String value, e.g. a placeholder
	 * or a {@link java.time.Duration#parse java.time.Duration} compliant value
	 * @since 3.2.2
	 *执行带注释的方法,其时间间隔为毫秒
	 *调用。
	 *@返回以毫秒为单位的字符串值,例如占位符
	 *或{@链接java.time.Duration解析java.time.Duration.持续时间}合规价值
	 *@从3.2.2开始
	 */
	String fixedRateString() default "";

	/**
	 * Number of milliseconds to delay before the first execution of a
	 * {@link #fixedRate} or {@link #fixedDelay} task.
	 * @return the initial delay in milliseconds
	 * @since 3.2
	 *在第一次执行之前要延迟的毫秒数
	 *{@link#fixedDate}或{@link#fixedDelay}任务。
	 *@返回初始延迟(毫秒)
	 *@从3.2开始
	 */
	long initialDelay() default -1;

	/**
	 * Number of milliseconds to delay before the first execution of a
	 * {@link #fixedRate} or {@link #fixedDelay} task.
	 * @return the initial delay in milliseconds as a String value, e.g. a placeholder
	 * or a {@link java.time.Duration#parse java.time.Duration} compliant value
	 * @since 3.2.2
	 *在第一次执行之前要延迟的毫秒数
	 *{@link#fixedDate}或{@link#fixedDelay}任务。
	 *@以字符串值的形式返回初始延迟(毫秒),例如占位符
	 *或{@链接java.time.Duration解析java.time.Duration.持续时间}合规价值
	 *@从3.2.2开始
	 */
	String initialDelayString() default "";

}

@EnableScheduling

这个注解需要加在启动类上,表示支持定时任务。

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Import(SchedulingConfiguration.class)
@Documented
public @interface EnableScheduling {

}

@PathVariable

通过 @PathVariable 可以将 URL 中占位符参数绑定到控制器处理方法的入参中:URL 中的 {xxx} 占位符可以通过@PathVariable(“xxx“) 绑定到操作方法的入参中。

@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface PathVariable {

	/**
	 * Alias for {@link #name}.
	 * {@link\name}的别名。
	 */
	@AliasFor("name")
	String value() default "";

	/**
	 * The name of the path variable to bind to.
	 * @since 4.3.3
	 *要绑定到的路径变量的名称。
	 *@从4.3.3开始
	 */
	@AliasFor("value")
	String name() default "";

	/**
	 * Whether the path variable is required.
	 * <p>Defaults to {@code true}, leading to an exception being thrown if the path
	 * variable is missing in the incoming request. Switch this to {@code false} if
	 * you prefer a {@code null} or Java 8 {@code java.util.Optional} in this case.
	 * e.g. on a {@code ModelAttribute} method which serves for different requests.
	 * @since 4.3.3
	 *是否需要路径变量。
	 *<p>默认为{@code true},如果路径
	 *传入请求中缺少变量。如果
	 *您更喜欢{@codenull}或Java8{@codejava.util.可选}在这种情况下。
	 *例如,在为不同请求服务的{@codemodelattribute}方法上。
	 *@从4.3.3开始
	 */
	boolean required() default true;

}

@RequestBody

这个一般处理的是在ajax请求中声明contentType: “application/json; charset=utf-8”时候。也就是json数据或者xml

@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface RequestBody {

	/**
	 * Whether body content is required.
	 * <p>Default is {@code true}, leading to an exception thrown in case
	 * there is no body content. Switch this to {@code false} if you prefer
	 * {@code null} to be passed when the body content is {@code null}.
	 * @since 3.2
	 *是否需要正文内容。
	 *<p>默认值是{@code true},这会导致在case中引发异常
	 *没有正文内容。如果愿意,请将其切换为{@code false}
	 *当正文内容为{@code null}时传递的{@code null}。
	 *@从3.2开始
	 */
	boolean required() default true;

}

@ResponseBody

将controller的方法返回的对象通过适当的转换器转换为指定的格式之后,写入到response对象的body区,通常用来返回JSON数据或者是XML数据。

@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface ResponseBody {

}

@RequestParam

这个一般就是在ajax里面没有声明contentType的时候,为默认的。。。urlencode格式时,用这个。

@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface RequestParam {

	/**
	 * Alias for {@link #name}.
	 *{@link\name}的别名。
	 */
	@AliasFor("name")
	String value() default "";

	/**
	 * The name of the request parameter to bind to.
	 * @since 4.2
	 *要绑定到的请求参数的名称。
	 *@从4.2开始
	 */
	@AliasFor("value")
	String name() default "";

	/**
	 * Whether the parameter is required.
	 * <p>Defaults to {@code true}, leading to an exception being thrown
	 * if the parameter is missing in the request. Switch this to
	 * {@code false} if you prefer a {@code null} value if the parameter is
	 * not present in the request.
	 * <p>Alternatively, provide a {@link #defaultValue}, which implicitly
	 * sets this flag to {@code false}.
	 *是否需要参数。
	 *<p>默认为{@code true},导致引发异常
	 *如果请求中缺少参数。把这个换成
	 *{@code false}如果参数是{@code null}值,则选择{@code false}
	 *请求中不存在。
	 *<p>或者,提供一个{@link#defaultValue},它隐式地
	 *将此标志设置为{@code false}。
	 */
	boolean required() default true;

	/**
	 * The default value to use as a fallback when the request parameter is
	 * not provided or has an empty value.
	 * <p>Supplying a default value implicitly sets {@link #required} to
	 * {@code false}.
	 *请求参数为时用作回退的默认值
	 *未提供或具有空值。
	 *<p>提供默认值将{@link#required}隐式设置为
	 *{@code false}。
	 */
	String defaultValue() default ValueConstants.DEFAULT_NONE;

}

@RequestMapping

是一个用来处理请求地址映射的注解,可用于类或方法上。

@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Mapping
public @interface RequestMapping {

	/**
	 * Assign a name to this mapping.
	 * <p><b>Supported at the type level as well as at the method level!</b>
	 * When used on both levels, a combined name is derived by concatenation
	 * with "#" as separator.
	 * @see org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder
	 * @see org.springframework.web.servlet.handler.HandlerMethodMappingNamingStrategy
	 *为此映射指定一个名称。
	 *<p><b>在类型级别和方法级别都支持!在</b>
	 *当在两个级别上使用时,组合名称是通过连接派生的
	 *以“#”作为分隔符。
	 *@看到了吗org.springframework.web.servlet.mvc.方法.annotation.MvcUriComponentsBuilder
	 *@看到了吗org.springframework.web.servlet.handler.HandlerMethodMappingNamingStrategy
	 */
	String name() default "";

	/**
	 * The primary mapping expressed by this annotation.
	 * <p>This is an alias for {@link #path}. For example,
	 * {@code @RequestMapping("/foo")} is equivalent to
	 * {@code @RequestMapping(path="/foo")}.
	 * <p><b>Supported at the type level as well as at the method level!</b>
	 * When used at the type level, all method-level mappings inherit
	 * this primary mapping, narrowing it for a specific handler method.
	 * <p><strong>NOTE</strong>: A handler method that is not mapped to any path
	 * explicitly is effectively mapped to an empty path.
	 *此批注表示的主映射。
	 *<p>这是{@link#path}的别名。例如,
	 *{@code@RequestMapping(“/foo”)}相当于
	 *{@code@RequestMapping(path=“/foo”)}。
	 *<p><b>在类型级别和方法级别都支持!在</b>
	 *在类型级别使用时,所有方法级映射都继承
	 *此主映射,将其缩小为特定的处理程序方法。
	 *<p><strong>注意</strong>:未映射到任何路径的处理程序方法
	 *显式地映射到空路径。
	 */
	@AliasFor("path")
	String[] value() default {};

	/**
	 * The path mapping URIs (e.g. {@code "/profile"}).
	 * <p>Ant-style path patterns are also supported (e.g. {@code "/profile/**"}).
	 * At the method level, relative paths (e.g. {@code "edit"}) are supported
	 * within the primary mapping expressed at the type level.
	 * Path mapping URIs may contain placeholders (e.g. <code>"/${profile_path}"</code>).
	 * <p><b>Supported at the type level as well as at the method level!</b>
	 * When used at the type level, all method-level mappings inherit
	 * this primary mapping, narrowing it for a specific handler method.
	 * <p><strong>NOTE</strong>: A handler method that is not mapped to any path
	 * explicitly is effectively mapped to an empty path.
	 * @since 4.2
	 *路径映射uri(例如{@code“/profile”})。
	 *<p>Ant风格的路径模式也受支持(例如{@code”/profile/**“})。
	 *在方法级别,支持相对路径(例如{@code“edit”})
	 *在类型级别表示的主映射中。
	 *路径映射uri可能包含占位符(例如<code>“/${profile\upath}”</code>)。
	 *<p><b>在类型级别和方法级别都支持!在</b>
	 *在类型级别使用时,所有方法级映射都继承
	 *此主映射,将其缩小为特定的处理程序方法。
	 *<p><strong>注意</strong>:未映射到任何路径的处理程序方法
	 *显式地映射到空路径。
	 *@从4.2开始
	 */
	@AliasFor("value")
	String[] path() default {};

	/**
	 * The HTTP request methods to map to, narrowing the primary mapping:
	 * GET, POST, HEAD, OPTIONS, PUT, PATCH, DELETE, TRACE.
	 * <p><b>Supported at the type level as well as at the method level!</b>
	 * When used at the type level, all method-level mappings inherit
	 * this HTTP method restriction (i.e. the type-level restriction
	 * gets checked before the handler method is even resolved).
	 *要映射到的HTTP请求方法,缩小了主映射范围:
	 *GET,POST,HEAD,OPTIONS,PUT,PATCH,DELETE,跟踪。
	 *<p><b>在类型级别和方法级别都支持!在</b>
	 *在类型级别使用时,所有方法级映射都继承
	 *此HTTP方法限制(即类型级别限制
	 *在解析处理程序方法之前进行检查)。
	 */
	RequestMethod[] method() default {};

	/**
	 * The parameters of the mapped request, narrowing the primary mapping.
	 * <p>Same format for any environment: a sequence of "myParam=myValue" style
	 * expressions, with a request only mapped if each such parameter is found
	 * to have the given value. Expressions can be negated by using the "!=" operator,
	 * as in "myParam!=myValue". "myParam" style expressions are also supported,
	 * with such parameters having to be present in the request (allowed to have
	 * any value). Finally, "!myParam" style expressions indicate that the
	 * specified parameter is <i>not</i> supposed to be present in the request.
	 * <p><b>Supported at the type level as well as at the method level!</b>
	 * When used at the type level, all method-level mappings inherit
	 * this parameter restriction (i.e. the type-level restriction
	 * gets checked before the handler method is even resolved).
	 * <p>Parameter mappings are considered as restrictions that are enforced at
	 * the type level. The primary path mapping (i.e. the specified URI value)
	 * still has to uniquely identify the target handler, with parameter mappings
	 * simply expressing preconditions for invoking the handler.
	 *映射请求的参数,缩小主映射范围。
	 *<p>任何环境的格式相同:“myParam=myValue”样式的序列
	 *表达式,只有在找到每个这样的参数时才映射请求
	 *得到给定的值。表达式可以用“!=“操作员,
	 *就像“myParam!=我的值“也支持myParam“样式表达式,
	 *这样的参数必须出现在请求中(允许
	 *任何值)。最后,“!myParam”样式表达式表示
	 *指定的参数不应存在于请求中。
	 *<p><b>在类型级别和方法级别都支持!在</b>
	 *在类型级别使用时,所有方法级映射都继承
	 *此参数限制(即类型级别限制
	 *在解析处理程序方法之前进行检查)。
	 *<p>参数映射被视为在
	 *类型级别。主路径映射(即指定的URI值)
	 *仍然必须使用参数映射唯一标识目标处理程序
	 *简单地表示调用处理程序的先决条件。
	 */
	String[] params() default {};

	/**
	 * The headers of the mapped request, narrowing the primary mapping.
	 * <p>Same format for any environment: a sequence of "My-Header=myValue" style
	 * expressions, with a request only mapped if each such header is found
	 * to have the given value. Expressions can be negated by using the "!=" operator,
	 * as in "My-Header!=myValue". "My-Header" style expressions are also supported,
	 * with such headers having to be present in the request (allowed to have
	 * any value). Finally, "!My-Header" style expressions indicate that the
	 * specified header is <i>not</i> supposed to be present in the request.
	 * <p>Also supports media type wildcards (*), for headers such as Accept
	 * and Content-Type. For instance,
	 * <pre class="code">
	 * &#064;RequestMapping(value = "/something", headers = "content-type=text/*")
	 * </pre>
	 * will match requests with a Content-Type of "text/html", "text/plain", etc.
	 * <p><b>Supported at the type level as well as at the method level!</b>
	 * When used at the type level, all method-level mappings inherit
	 * this header restriction (i.e. the type-level restriction
	 * gets checked before the handler method is even resolved).
	 * @see org.springframework.http.MediaType
	 *映射请求的头,缩小主映射范围。
	 *<p>任何环境的格式相同:“My Header=myValue”样式的序列
	 *表达式,只有在找到每个这样的头时才映射请求
	 *得到给定的值。表达式可以用“!=“操作员,
	 *就像“我的头!=我的值“也支持My Header“样式表达式,
	 *这样的头必须出现在请求中(允许
	 *任何值)。最后,“!“MyHeader”样式表达式表示
	 *指定的标头不应存在于请求中。
	 *<p>还支持媒体类型通配符(*),例如Accept
	 *和内容类型。例如,
	 *<pre class=“code”>
	 *&amp;#064;请求映射(value=“/something”,headers=“content type=text/*”)
	 *</pre>
	 *将匹配内容类型为“text/html”、“text/plain”等的请求。
	 *<p><b>在类型级别和方法级别都支持!在</b>
	 *在类型级别使用时,所有方法级映射都继承
	 *此标头限制(即类型级别限制
	 *在解析处理程序方法之前进行检查)。
	 *@看到了吗org.springframework.http.媒体类型
	 */
	String[] headers() default {};

	/**
	 * Narrows the primary mapping by media types that can be consumed by the
	 * mapped handler. Consists of one or more media types one of which must
	 * match to the request {@code Content-Type} header. Examples:
	 * <pre class="code">
	 * consumes = "text/plain"
	 * consumes = {"text/plain", "application/*"}
	 * consumes = MediaType.TEXT_PLAIN_VALUE
	 * </pre>
	 * Expressions can be negated by using the "!" operator, as in
	 * "!text/plain", which matches all requests with a {@code Content-Type}
	 * other than "text/plain".
	 * <p><b>Supported at the type level as well as at the method level!</b>
	 * If specified at both levels, the method level consumes condition overrides
	 * the type level condition.
	 * @see org.springframework.http.MediaType
	 * @see javax.servlet.http.HttpServletRequest#getContentType()
	 *按可由使用的媒体类型缩小主映射
	 *映射处理程序。由一种或多种媒体类型组成,其中一种必须
	 *与请求{@code Content Type}头匹配。示例:
	 *<pre class=“code”>
	 *consumes=“文本/plain”
	 *consumes={“text/plain”,“application/*”}
	 *消耗=MediaType.TEXT_普通值
	 *</pre>
	 *可以使用“!”来否定表达式操作员,如
	 * "!text/plain”,它将所有请求与{@code Content Type}匹配
	 *而不是“文本/纯文本”。
	 *<p><b>在类型级别和方法级别都支持!在</b>
	 *如果在两个级别指定,则方法级别使用条件重写
	 *类型级别条件。
	 *@看到了吗org.springframework.http.媒体类型
	 *@看到了吗javax.servlet.http.HttpServletRequest\getContentType()
	 */
	String[] consumes() default {};

	/**
	 * Narrows the primary mapping by media types that can be produced by the
	 * mapped handler. Consists of one or more media types one of which must
	 * be chosen via content negotiation against the "acceptable" media types
	 * of the request. Typically those are extracted from the {@code "Accept"}
	 * header but may be derived from query parameters, or other. Examples:
	 * <pre class="code">
	 * produces = "text/plain"
	 * produces = {"text/plain", "application/*"}
	 * produces = MediaType.TEXT_PLAIN_VALUE
	 * produces = "text/plain;charset=UTF-8"
	 * </pre>
	 * <p>If a declared media type contains a parameter (e.g. "charset=UTF-8",
	 * "type=feed", type="entry") and if a compatible media type from the request
	 * has that parameter too, then the parameter values must match. Otherwise
	 * if the media type from the request does not contain the parameter, it is
	 * assumed the client accepts any value.
	 * <p>Expressions can be negated by using the "!" operator, as in "!text/plain",
	 * which matches all requests with a {@code Accept} other than "text/plain".
	 * <p><b>Supported at the type level as well as at the method level!</b>
	 * If specified at both levels, the method level produces condition overrides
	 * the type level condition.
	 * @see org.springframework.http.MediaType
	 * @see org.springframework.http.MediaType
	 *按可由生成的媒体类型缩小主映射
	 *映射处理程序。由一种或多种媒体类型组成,其中一种必须
	 *通过内容协商与“可接受”媒体类型进行选择
	 *请求的。通常这些都是从{@code“Accept”}中提取的
	 *但可以从查询参数或其他派生。示例:
	 *<pre class=“code”>
	 *products=“文本/纯文本”
	 *产生={“text/plain”,“application/*”}
	 *生产=MediaType.TEXT_普通值
	 *products=“text/plain;字符集=UTF-8”
	 *</pre>
	 *<p>如果声明的媒体类型包含参数(例如“charset=UTF-8”,
	 *“type=feed”,type=“entry”),如果请求中有兼容的媒体类型
	 *也有该参数,则参数值必须匹配。否则
	 *如果请求中的媒体类型不包含参数,则为
	 *假设客户接受任何价值。
	 *<p>可以使用“!”对表达式求反操作员,如“!文本/纯文本“,
	 *它与除“text/plain”之外的{@code Accept}匹配所有请求。
	 *<p><b>在类型级别和方法级别都支持!在</b>
	 *如果在两个级别指定,则方法级别将生成条件重写
	 *类型级别条件。
	 *@看到了吗org.springframework.http.媒体类型
	 *@看到了吗org.springframework.http.媒体类型
	 */
	String[] produces() default {};

}

@PostMapping

一个组合注解,是@RequestMapping(method = RequestMethod.POST)的缩写。

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@RequestMapping(method = RequestMethod.POST)
public @interface PostMapping {

	/**
	 * Alias for {@link RequestMapping#name}.
	 * {@link RequestMapping\name}的别名。
	 */
	@AliasFor(annotation = RequestMapping.class)
	String name() default "";

	/**
	 * Alias for {@link RequestMapping#value}.
	 * {@link RequestMapping\value}的别名。
	 */
	@AliasFor(annotation = RequestMapping.class)
	String[] value() default {};

	/**
	 * Alias for {@link RequestMapping#path}.
	 * {@link RequestMapping\path}的别名。
	 */
	@AliasFor(annotation = RequestMapping.class)
	String[] path() default {};

	/**
	 * Alias for {@link RequestMapping#params}.
	 * {@link RequestMapping\params}的别名。
	 */
	@AliasFor(annotation = RequestMapping.class)
	String[] params() default {};

	/**
	 * Alias for {@link RequestMapping#headers}.
	 * {@link RequestMapping\headers}的别名。
	 */
	@AliasFor(annotation = RequestMapping.class)
	String[] headers() default {};

	/**
	 * Alias for {@link RequestMapping#consumes}.
	 * {@link RequestMapping\consumes}的别名。
	 */
	@AliasFor(annotation = RequestMapping.class)
	String[] consumes() default {};

	/**
	 * Alias for {@link RequestMapping#produces}.
	 * {@link RequestMapping\produces}的别名。
	 */
	@AliasFor(annotation = RequestMapping.class)
	String[] produces() default {};

}

@GetMapping

一个组合注解,是@RequestMapping(method = RequestMethod.GET)的缩写。

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@RequestMapping(method = RequestMethod.POST)
public @interface GetMapping {

	/**
	 * Alias for {@link RequestMapping#name}.
	 * {@link RequestMapping\name}的别名。
	 */
	@AliasFor(annotation = RequestMapping.class)
	String name() default "";

	/**
	 * Alias for {@link RequestMapping#value}.
	 * {@link RequestMapping\value}的别名。
	 */
	@AliasFor(annotation = RequestMapping.class)
	String[] value() default {};

	/**
	 * Alias for {@link RequestMapping#path}.
	 * {@link RequestMapping\path}的别名。
	 */
	@AliasFor(annotation = RequestMapping.class)
	String[] path() default {};

	/**
	 * Alias for {@link RequestMapping#params}.
	 * {@link RequestMapping\params}的别名。
	 */
	@AliasFor(annotation = RequestMapping.class)
	String[] params() default {};

	/**
	 * Alias for {@link RequestMapping#headers}.
	 * {@link RequestMapping\headers}的别名。
	 */
	@AliasFor(annotation = RequestMapping.class)
	String[] headers() default {};

	/**
	 * Alias for {@link RequestMapping#consumes}.
	 * {@link RequestMapping\consumes}的别名。
	 */
	@AliasFor(annotation = RequestMapping.class)
	String[] consumes() default {};

	/**
	 * Alias for {@link RequestMapping#produces}.
	 * {@link RequestMapping\produces}的别名。
	 */
	@AliasFor(annotation = RequestMapping.class)
	String[] produces() default {};

}

@target

通常用在生命自定义一个新的注解时使用,用来定义这个自定义的注解可以作用在什么上面,比如类、接口、注解、枚举, 字段, 普通方法, 参数, 构造方法, 局部变量, 注解, 包

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
public @interface Target {
    /**
     * Returns an array of the kinds of elements an annotation type
     * can be applied to.
     * @return an array of the kinds of elements an annotation type
     * can be applied to
     *返回批注类型的元素类型的数组
	 *可以应用于。
	 *@返回注释类型元素的数组
	 *可应用于
     */
    ElementType[] value();
}

@Retention

Reteniton的作用是定义被它所注解的注解保留多久,一共有三种策略,定义在RetentionPolicy枚举中

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
public @interface Retention {
    /**
     * Returns the retention policy.
     * @return the retention policy
     *返回保留策略。
	 *@返回保留策略
     */
    RetentionPolicy value();
}


public enum RetentionPolicy {
    /**
     * Annotations are to be discarded by the compiler.
     * 注释将被编译器丢弃。
     */
    SOURCE,

    /**
     * Annotations are to be recorded in the class file by the compiler
     * but need not be retained by the VM at run time.  This is the default
     * behavior.
     *注释将由编译器记录在类文件中
	 *但不需要在运行时被VM保留。这是默认值
	 *行为。
     */
    CLASS,

    /**
     * Annotations are to be recorded in the class file by the compiler and
     * retained by the VM at run time, so they may be read reflectively.
     *
     * @see java.lang.reflect.AnnotatedElement
     *注释将由编译器记录在类文件中,并且
	 *在运行时被VM保留,因此可以反射性地读取它们。
	 *
	 *@看到了吗java.lang.reflect.注释删除
     */
    RUNTIME
}

@Inherited

使用此注解声明出来的自定义注解,在使用此自定义注解时,如果注解在类上面时,子类会自动继承此注解,否则的话,子类不会继承此注解。这里一定要记住,使用Inherited声明出来的注解,只有在类上使用时才会有效,对方法,属性等其他无效。

/**
 * Indicates that an annotation type is automatically inherited.  If
 * an Inherited meta-annotation is present on an annotation type
 * declaration, and the user queries the annotation type on a class
 * declaration, and the class declaration has no annotation for this type,
 * then the class's superclass will automatically be queried for the
 * annotation type.  This process will be repeated until an annotation for this
 * type is found, or the top of the class hierarchy (Object)
 * is reached.  If no superclass has an annotation for this type, then
 * the query will indicate that the class in question has no such annotation.
 *
 * <p>Note that this meta-annotation type has no effect if the annotated
 * type is used to annotate anything other than a class.  Note also
 * that this meta-annotation only causes annotations to be inherited
 * from superclasses; annotations on implemented interfaces have no
 * effect.
 *指示自动继承批注类型。如果
 *批注类型上存在继承的元批注
 *声明,并且用户查询类上的注释类型
 *声明,而类声明没有此类型的注释,
 *然后类的超类将自动查询
 *批注类型。此过程将重复,直到对此进行注释
 *找到类型,或类层次结构(对象)的顶部
 *已到达。如果没有超类具有此类型的注释,则
 *查询将指示相关类没有此类注释。
 *
 *<p>请注意,如果
 *类型用于注释类以外的任何内容。也请注意
 *这个元注释只会导致注释被继承
 *从超类;实现接口上的注释没有
 *效果。
 *
 * @author  Joshua Bloch
 * @since 1.5
 * @jls 9.6.3.3 @Inherited
 */
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
public @interface Inherited {
}

@Profile

注解在方法类上在不同情况下选择实例化不同的Bean特定环境下生效!

@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Conditional(ProfileCondition.class)
public @interface Profile {

	/**
	 * The set of profiles for which the annotated component should be registered.
	 *应为其注册带注释组件的配置文件集。
	 */
	String[] value();

}

@SuppressWarnings

抑制警告

@Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE})
@Retention(RetentionPolicy.SOURCE)
public @interface SuppressWarnings {
    /**
     * The set of warnings that are to be suppressed by the compiler in the
     * annotated element.  Duplicate names are permitted.  The second and
     * successive occurrences of a name are ignored.  The presence of
     * unrecognized warning names is <i>not</i> an error: Compilers must
     * ignore any warning names they do not recognize.  They are, however,
     * free to emit a warning if an annotation contains an unrecognized
     * warning name.
     *
     * <p> The string {@code "unchecked"} is used to suppress
     * unchecked warnings. Compiler vendors should document the
     * additional warning names they support in conjunction with this
     * annotation type. They are encouraged to cooperate to ensure
     * that the same names work across multiple compilers.
     * @return the set of warnings to be suppressed
     *中编译器要禁止的警告集
	 *带注释的元素。允许重复名称。第二个和
	 *将忽略连续出现的名称。存在
	 *无法识别的警告名称是<i>不是</i>错误:编译器必须
	 *忽略他们无法识别的任何警告名称。但是,他们是,
	 *如果批注包含无法识别的
	 *警告名称。
	 *
	 *<p>字符串{@code“unchecked”}用于抑制
	 *未经检查的警告。编译器供应商应记录
	 *它们支持与此相关的其他警告名称
	 *批注类型。鼓励他们合作以确保
	 *在多个编译器中使用相同的名称。
	 *@返回要抑制的警告集
     */
    String[] value();
}

@Modifying

如果是增,改,删加上此注解

  1. 方法的返回值应该是int,表示更新语句所影响的行数。
  2. 在调用的地方必须加事务,没有事务不能正常执行。@Transactional 事务注解
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值