springboot注解

@SpringBootApplication

声明让springboot进行自动配置,用于注解类

@SpringBootApplication=@Configuration+@EnableAutoConfiguration+@ComponentScan

@Configuration

声明项目的配置类

@EnableAutoConfiguration

用于自动配置

@ComponentScan

用于自动发现和装配bean

@Import

用来导入其他配置类

@ImportResource

用来加载xml配置文件

@ResponseBody

将返回结果写入HTTP response body,用于注解方法,一般在异步获取数据时使用,用于构建RESTful的api。不加@ResponseBody时,返回结果解析为路径跳转

@Controller

定义控制器,用于注解类,在spring 项目中由控制器负责将用户发来的URL请求转发到对应的服务接口(service层)

@RestController

用于标注控制层组件(如struts中的action)

@RestController=@ResponseBody+@Controller

@RequestMapping

提供路由信息,负责URL到Controller中的具体函数的映射

@Autowired和@Inject

两个注解都用来自动导入依赖的bean,只是@Inject注解没有required属性

@Compoent和@bean

@Component and its specializations (@Controller, @Service and @Repository) allow for auto-detection using classpath scanning.

Annotation Purpose Annotation Purpose
@Component A candidate for auto-detection via classpath scanning. @Component A candidate for auto-detection via classpath scanning.
@Controller A web controller, popularized by Spring MVC. @Controller A web controller, popularized by Spring MVC.
@Repository Data manager / storage, ties to enterprise apps (DAO, DDD) @Repository Data manager / storage, ties to enterprise apps (DAO, DDD)
@Service Meant to provide business logic – a (stateless) facade. @Service Meant to provide business logic – a (stateless) facade.

@Bean on the other hand can only be used to explicitly declare a single bean in a configuration class.

@Qualifier

与@Autowired配合使用,当有多个同一类型的bean时,可以用@Qualifier(“name”)来指定。

你可能感兴趣的:(springboot注解)