SpringBoot之一些注解说明汇总

本文详细介绍了Spring Boot中常用的注解,包括 @RequestMapping 和 @RestController 的功能区别,以及 @EnableAutoConfiguration 和 @ComponentScan 的作用。同时展示了如何通过 @SpringBootApplication 标记主类,并提供了排除特定自动配置类的方法。

@RequestMapping 注解提供路由router功能;作为MVC中的控制器;

@RestController 注解除了上面的路由router功能,且还会将结果render到前端;

一般是String类型,返回String数据;

复杂类型返回json数据;

 @EnableAutoConfiguration 注解让spring容器根据用户引入的jar包,猜想用户的应用类型;

比如引入了spring-boot-startr-web,Spring容易会认为当前是一个web应用;

@CompoentScan 注解扫描业务注解类,包含controller,service等等;

如果application默认在根目录则不要配置该注解;

默认扫描整个目录工程;

com
 +- example
     +- myproject
         +- Application.java
         |
         +- domain
         |   +- Customer.java
         |   +- CustomerRepository.java
         |
         +- service
         |   +- CustomerService.java
         |
         +- web
             +- CustomerController.java

持续补充。。。。 

@SpringBootApplication 注解标注当前类是springboot的入口类;

等价于:

@Configuration
@EnableAutoConfiguration
@ComponentScan

@EnableAutoConfiguration 注解,去掉不想引用的类;如下:

import org.springframework.boot.autoconfigure.*;
import org.springframework.boot.autoconfigure.jdbc.*;
import org.springframework.context.annotation.*;

@Configuration
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
public class MyConfiguration {
}

 

转载于:https://my.oschina.net/boreboluomiduo/blog/866503

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值