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”)来指定。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 正文小计363字,需耗费你约1分38秒才能看完,灵感:心中的爱情誓言,么用:用于装饰爱情,用于热恋的每个感动。 谁...
    辉辉大诗阅读 452评论 0 0
  • 在轻飘飘的时光里,脑子是最容易沉重。一遍又一遍的刷着今日头条,一边在心里骂着自己无耻,一边又机械的上下滑动。人总是...
    草小孟阅读 140评论 2 0