(1)@SpringBootApplication

申明让spring boot自动给程序进行必要的配置,这个配置等同于:

@Configuration ,@EnableAutoConfiguration 和 @ComponentScan 三个配置。

这个具体可以查看博客:

(32)Spring Boot使用@SpringBootApplication注解,从零开始学Spring Boot

示例代码:

package com.kfit;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

/**

*

@author

@version v.0.1

@date

*/

@SpringBootApplication

publicclass App {

publicstaticvoid main(String[] args) {

SpringApplication.run(ApiCoreApp.class, args);

}

}

(2)@ResponseBody

该注解修饰的函数,会将结果直接填充到HTTP的响应体中,一般用于构建RESTful的api,该注解一般会配合@RequestMapping一起使用。

示例代码:

@RequestMapping("/test")

@ResponseBody

public String test(){

return"ok";

}

(3)@Controller

用于定义控制器类,在spring 项目中由控制器负责将用户发来的URL请求转发到对应的服务接口(service层),一般这个注解在类中,通常方法需要配合注解@RequestMapping。

示例代码:

@Controller

@RequestMapping("/demoInfo")

publicclass DemoController {

@Autowired

private DemoInfoService demoInfoService;

@RequestMapping("/hello")

public String hello(Map<String,Object> map){

System.out.println("DemoController.hello()");

map.put("hello","from TemplateController.helloHtml");

//会使用hello.html或者hello.ftl模板进行渲染显示.

return"/hello";

}

}

(4)@RestController

@ResponseBody和@Controller的合集

示例代码:

package com.kfit.demo.web;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**

*

@author Angel(QQ交流群:193341332,QQ:412887952)

@version v.0.1

@date 2016年7月29日下午7:26:04

*/

@RestController

@RequestMapping("/demoInfo2")

publicclass DemoController2 {

@RequestMapping("/test")

public String test(){

return"ok";

}

}

(5)@RequestMapping

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

(6)@EnableAutoConfiguration

Spring Boot自动配置(auto-configuration):尝试根据你添加的jar依赖自动配置你的Spring应用。例如,如果你的classpath下存在HSQLDB,并且你没有手动配置任何数据库连接beans,那么我们将自动配置一个内存型(in-memory)数据库”。你可以将@EnableAutoConfiguration或者@SpringBootApplication注解添加到一个@Configuration类上来选择自动配置。如果发现应用了你不想要的特定自动配置类,你可以使用@EnableAutoConfiguration注解的排除属性来禁用它们。

(7)@ComponentScan 

表示将该类自动发现(扫描)并注册为Bean,可以自动收集所有的Spring组件,包括@Configuration类。我们经常使用@ComponentScan注解搜索beans,并结合@Autowired注解导入。如果没有配置的话,Spring Boot会扫描启动类所在包下以及子包下的使用了@Service,@Repository等注解的类。

(8)@Configuration

相当于传统的xml配置文件,如果有些第三方库需要用到xml文件,建议仍然通过@Configuration类作为项目的配置主类——可以使用@ImportResource注解加载xml配置文件。

(9)@Import

用来导入其他配置类。

(10)@ImportResource

用来加载xml配置文件。

(11)@Autowired

自动导入依赖的bean

(12)@Service

一般用于修饰service层的组件

(13)@Repository

使用@Repository注解可以确保DAO或者repositories提供异常转译,这个注解修饰的DAO或者repositories类会被ComponetScan发现并配置,同时也不需要为它们提供XML配置项。

(14)@Bean

用@Bean标注方法等价于XML中配置的bean。

(15)@Value

注入Spring boot application.properties配置的属性的值。

示例代码: @Value(value = "#{message}")

private String message;

(16)@Qualifier

@Qualifier限定描述符除了能根据名字进行注入,但能进行更细粒度的控制如何选择候选者,具体使用方式如下:

@Autowired

@Qualifier(value = "demoInfoService")

private DemoInfoService demoInfoService;

(17)@Inject

等价于默认的@Autowired,只是没有required属性;

Spring Boot注解(annotation)列表的更多相关文章

  1. 73. Spring Boot注解(annotation)列表【从零开始学Spring Boot】

    [从零开始学习Spirng Boot-常见异常汇总] 针对于Spring Boot提供的注解,如果没有好好研究一下的话,那么想应用自如Spring Boot的话,还是有点困难的,所以我们这小节,说说S ...

  2. Spring boot注解(annotation)含义详解

    Spring boot注解(annotation)含义详解 @Service用于标注业务层组件@Controller用于标注控制层组件(如struts中的action)@Repository用于标注数 ...

  3. Spring Boot注解大全,一键收藏了!

    本文首发于微信公众号[猿灯塔],转载引用请说明出处 今天是猿灯塔“365天原创计划”第5天. 今天呢!灯塔君跟大家讲: Spring Boot注解大全 一.注解(annotations)列表 @Spr ...

  4. Spring boot 注解简单备忘

    Spring boot 注解简单备忘 1.定义注解 package com.space.aspect.anno;import java.lang.annotation.*; /** * 定义系统日志注 ...

  5. spring boot Configuration Annotation Proessor not found in classpath

    出现spring boot Configuration Annotation Proessor not found in classpath的提示是在用了@ConfigurationPropertie ...

  6. Spring Boot Configuration Annotation Proessor not found in classpath解决办法

    From: https://www.cnblogs.com/whtgjy/p/9438317.html 出现spring boot Configuration Annotation Proessor ...

  7. 解决spring boot1.5以上版本@ConfigurationProperties提示“Spring Boot Configuration Annotation Processor not.."

    Springboot1.5以上版本,在使用 @ConfigurationProperties注解的时候会提示“Spring Boot Configuration Annotation Processo ...

  8. (转)Spring对注解(Annotation)处理源码分析1——扫描和读取Bean定义

    1.从Spring2.0以后的版本中,Spring也引入了基于注解(Annotation)方式的配置,注解(Annotation)是JDK1.5中引入的一个新特性,用于简化Bean的配置,某些场合可以 ...

  9. Spring Boot 注解之ObjectProvider源码追踪

    最近依旧在学习阅读Spring Boot的源代码,在此过程中涉及到很多在日常项目中比较少见的功能特性,对此深入研究一下,也挺有意思,这也是阅读源码的魅力之一.这里写成文章,分享给大家. 自动配置中的O ...

随机推荐

  1. oracle 三表关联查询

      oracle 三表关联查询 CreationTime--2018年7月4日17点52分 Author:Marydon 左连接实现三表关联 表A--------------------------- ...

  2. 解析drupal_render()

    drupal_render()函数接收一个结构化的数组作为参数,然后调用theme()输出HTML. function drupal_render(&$elements) { ... ... ...

  3. 【PHP】在目标字符串指定位置插入字符串

    PHP如何在指定位置插入相关字符串,例子:123456789变为1_23_456789插入"_"到指定的位置! (可以用作换行或者其他处理) 插入示例,具体思路在代码中有注释: & ...

  4. 【LeetCode】98. Validate Binary Search Tree (2 solutions)

    Validate Binary Search Tree Given a binary tree, determine if it is a valid binary search tree (BST) ...

  5. FFmpeg 向视频中添加文字

    原文地址:http://www.cnblogs.com/wanggang123/p/6707985.html FFmpeg支持添加文字功能,具体如何将文字叠加到视频中的每一张图片,FFmpeg调用了文 ...

  6. C与C++中非常少犯的错误,犯了后却非常难找出的错误

    1.continue,break类的错误(HDU1877): #include<iostream> using namespace std; int main() { int a,b,m, ...

  7. 一名全栈工程师Node.js之路-转

    Node.js 全球现状 虽然 Node.js 在国内没有盛行,但据 StackOverflow 2016 年开发者调查,其中 node.js .全栈.JavaScript 相关的技术在多个领域(包括 ...

  8. zoj 1562 反素数 附上个人对反素数性质的证明

    反素数的定义:对于不论什么正整数,其约数个数记为.比如,假设某个正整数满足:对随意的正整 数.都有,那么称为反素数. 从反素数的定义中能够看出两个性质: (1)一个反素数的全部质因子必定是从2開始的连 ...

  9. 每日英语:Stalled Project Shows Why China's Economy Is Wobbling

    CAOFEIDIAN, China  $91 billion industrial project here, mired in debt and unfulfilled promise, sugge ...

  10. hadoop三大组件的简单图解

    如有不对,欢迎大家指正