Spring Boot Annotation

@SpringBootApplication

  必须作用在main 方法所在类

@RequestMapping @GetMapping @PostMapping ...

  配置URL映射

@Controller  

  处理HTTP请求

@RestController

  等同于@Controller  + @ResponseBody

@Value("${配置文件application.properties中的属性名}")

@ConfigurationProperties

  实例:  

    application.properties配置如下:

          server.port=8080

          server.testAttribute=ZZZ

       java:

         //省去了用@Value 对类成员一个个注解的麻烦

         @ConfigurationProperties(prefix="server")

       public class ServerProperties(){

         private String port;

         private String testAttribute

       }

@Component 

  作用于类  将类讲给Spring管理,便于其他Spring注解处用到该类

  注:在持久层、业务层和控制层中,分别采用@Repository、@Service和@Controller对分层中的类进行凝视,而用@Component对那些比较中立的类进行凝视。

@Autowired  @Resource

  修饰字段、构造函数或者设置方法,用于注入

  @Autowired

  private ServerProperties serverProperties;  //无需自己new对象,由@Autowired告知Spring自动注入

  注:@Autowired默认按类型装配

      如果要允许null值 - @Autowired(required=false)

      使用名称装配 - @Autowired() @Qualifier("bean的name")    

      存疑:Spring Boot 用@Component注解的bean 的 name 是什么,不是没有bean的配置文件吗?

@Valid

  表单验证,并将验证结果填入BindingResult

Spring Annotation(注解)的更多相关文章

  1. Spring Annotation注解进行aop的学习

    使用Maven管理项目,pom文件为: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=" ...

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

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

  3. Spring的声明式事务----Annotation注解方式(2)

    使用步骤: 步骤一.在spring配置文件中引入<tx:>命名空间<beans xmlns="http://www.springframework.org/schema/b ...

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

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

  5. Spring对注解(Annotation)处理【转】

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

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

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

  7. 吴裕雄--天生自然JAVA SPRING框架开发学习笔记:Spring声明式事务管理(基于Annotation注解方式实现)

    在 Spring 中,除了使用基于 XML 的方式可以实现声明式事务管理以外,还可以通过 Annotation 注解的方式实现声明式事务管理. 使用 Annotation 的方式非常简单,只需要在项目 ...

  8. Spring系列之Spring常用注解总结

    传统的Spring做法是使用.xml文件来对bean进行注入或者是配置aop.事物,这么做有两个缺点:1.如果所有的内容都配置在.xml文件中,那么.xml文件将会十分庞大:如果按需求分开.xml文件 ...

  9. spring @condition 注解

    spring @condition注解是用来在不同条件下注入不同实现的 demo如下: package com.foreveross.service.weixin.test.condition; im ...

  10. spring mvc(注解)上传文件的简单例子

    spring mvc(注解)上传文件的简单例子,这有几个需要注意的地方1.form的enctype=”multipart/form-data” 这个是上传文件必须的2.applicationConte ...

随机推荐

  1. Learning from Imbalanced Classes

    https://www.svds.com/learning-imbalanced-classes/ 下采样即 从大类负类中随机取一部分,跟正类(小类)个数相同,优点就是降低了内存大小,速度快! htt ...

  2. Ubuntu 14.04 安装配置强大的星际译王(stardict)词典

    转载http://blog.csdn.net/huyisu/article/details/53437931

  3. Asp.net MVC获取访问系统的客户端计算机的主机名和IP地址

    string HostName = string.Empty; string ip = string.Empty; string ipv4 = String.Empty; if (!string.Is ...

  4. .Net 数据库(SqlServer2008)的备份、还原

    //备份代码private void Backup() { SqlConnection sqlConn = new SqlConnection(strConn); strFileName = &quo ...

  5. Spring jdbcTemplate RowMapper绑定任意对象

    RowMapper可以将数据中的每一行封装成用户定义的类,在数据库查询中,如果返回的类型是用户自定义的类型则需要包装,如果是Java自定义的类型,如:String则不需要,Spring最新的类Simp ...

  6. C# 读取Text文本,写入Text文本

    //读取 private void showMess() { this.dataGridViewX2.Rows.Clear(); //将车辆信息一行行添加到datagreatview 里面 Strea ...

  7. 基于verilog的FFT算法8点12位硬件实现

    FFT算法8点12位硬件实现 (verilog) 1 一.功能描述: 1 二.设计结构: 2 三.设计模块介绍 3 1.蝶形运算(第一级) 3 2.矢量角度旋转(W) 4 3.CORDIC 结果处理 ...

  8. ARKit入门

    ARKit介绍 ARKit是iOS11引入的一个全新的框架,使用Visual Inertial Odometry(VIO,视觉惯性里程计)来精确跟踪现实世界中的真实场景.相比其它设备平台,ARKit中 ...

  9. 和Webbrowser进行简单交互

    作为第一篇,简单的控件使用就不说了. 直接从简单的交互开始吧! C#使用网页中已有的js函数 webBrowser.Document.InvokeScript("Stop");// ...

  10. Jenkins忘记密码

    当Jenkins密码忘记时,可以去Jenkins的安装目录下的users\用户名_xxxxx\config.conf文件下找下找到<passwordHash></passwordHa ...