(1)@SpringBootApplication

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

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

这个具体可以查看博客:

示例代码:

package com.kfit;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

/**

*

@author Angel(QQ交流群:193341332)

@version v.0.1

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

*/

@SpringBootApplication

public class App {

public static void 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")

public class 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")

public class 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属性;

170721、springboot编程之注解(annotation)列表的更多相关文章

  1. Spring Boot注解(annotation)列表

    (1)@SpringBootApplication 申明让spring boot自动给程序进行必要的配置,这个配置等同于: @Configuration ,@EnableAutoConfigurati ...

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

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

  3. springboot编程之全局异常捕获

    springboot编程之全局异常捕获 1.创建GlobalExceptionHandler.java,在类上注解@ControllerAdvice, 在方法上注解@ExceptionHandler( ...

  4. JAVA提高五:注解Annotation

    今天我们学习JDK5.0中一个非常重要的特性,叫做注解.是现在非常流行的一种方式,可以说因为配置XML 比较麻烦或者比容易查找出错误,现在越来越多的框架开始支持注解方式,比如注明的Spring 框架, ...

  5. Java并发注解Annotation

    Java并发编程中,用到了一些专门为并发编程准备的 Annotation. 主要包括三类: 1.类 Annotation(注解) 就像名字一样,这些注解是针对类的.主有要以下三个: @Immutabl ...

  6. 秒懂,Java 注解 (Annotation)你可以这样学 - CSDN博客

    https://blog.csdn.net/briblue/article/details/73824058 文章开头先引入一处图片. 这处图片引自老罗的博客.为了避免不必要的麻烦,首先声明我个人比较 ...

  7. springboot aop 自定义注解方式实现完善日志记录(完整源码)

    版权声明:本文为博主原创文章,欢迎转载,转载请注明作者.原文超链接 一:功能简介 本文主要记录如何使用aop切面的方式来实现日志记录功能. 主要记录的信息有: 操作人,方法名,参数,运行时间,操作类型 ...

  8. springboot aop 自定义注解方式实现一套完善的日志记录(完整源码)

    https://www.cnblogs.com/wenjunwei/p/9639909.html https://blog.csdn.net/tyrant_800/article/details/78 ...

  9. Java自定义数据验证注解Annotation

    本文转载自:https://www.jianshu.com/p/616924cd07e6 Java注解Annotation用起来很方便,也越来越流行,由于其简单.简练且易于使用等特点,很多开发工具都提 ...

随机推荐

  1. 关于Cocos2d-x中的scheduleUpdate和update方法的使用

    一.如果要让某类实例对象要连续执行某些语句(比如让每个Block实例从运行框最右边移动到最左边) 要在Block类中增加一些东西 1.先在其.cpp文件的init()函数中执行scheduleUpda ...

  2. MongoDB状态查询:db.serverStatus()

    参见:http://www.2cto.com/database/201501/370191.html 基本信息 spock:PRIMARY>db.serverStatus() { "h ...

  3. e641. 使一个组件成为拖放目标

    public class DropTargetComponent extends JComponent implements DropTargetListener { public DropTarge ...

  4. 科技发烧友之3d吉米投影

    http://item.jd.com/1558081.html?r=1434635270480#comment 暴风199的墨镜

  5. Unity简介

    Unity (也称 nity3D) 是一套包括图形. 声音.物理等功能的游戏引擎,提供了一个强大的关卡编辑器,支持大部分主流 3D 软件格式,使用 C# JavaScript 等高级语言实现脚本功能, ...

  6. cake build使用:

    开源地址: https://github.com/cake-build/cake 依赖 powershell 3.0 Windows 获取引导程序: Invoke-WebRequest http:// ...

  7. highchart的用法积累

    highcharts 柱子换颜色 var colors = Highcharts.getOptions().colors; $(arr_Y_bfb).each(function (index, ele ...

  8. 【Java集合的详细研究5】Java中Array与ArrayList的主要区别

    1)精辟阐述:可以将 ArrayList想象成一种“会自动扩增容量的Array”. 2)Array([]):最高效:但是其容量固定且无法动态改变:     ArrayList:  容量可动态增长:但牺 ...

  9. spark on yarn(zookeeper 配置)

    http://database.51cto.com/art/201404/435630.htm

  10. 【转】如何读懂Oracle文档中的语法图

    转自:http://blog.itpub.net/22990797/viewspace-750157/ Oracle文档中用到了两种表达语法的方法,语法图和BNF. BNF, Backus-Naur ...