| 注解 |
解释 |
| @RestController |
(组合了@Controller和@ResponseBody注解)原来在@Controller中返回json需要@ResponseBody来配合,如果直接用@RestController替代@Controller就不需要再配置@ResponseBody,默认返回json格式。 |
| @Controller |
(组合了@Component注解)标识一个该类是Spring MVC controller处理器,用来创建处理http请求的对象.DispatcherServlet会自动扫描注解了此注解的类,然后将web请求映射到注解了@RequestMapping的方法上。 |
| @Service |
(组合了@Component注解),用于标注业务层组件。 |
| @Reponsitory |
(组合了@Component注解),应用在dao层(数据访问层)。 |
| @RequestMapping |
用来映射web请求(访问路径和参数),处理类和方法的。可以注解在类和方法上,注解在方法上的@RequestMapping路径会继承注解在类上的路径。 |
| @Component |
元注解。表示类是一个“组件”,会成为Spring管理的Bean。 |
| @PathVariable |
放置在接收参数前,用来接受路径参数。 |
| @RequestParam |
用于将请求参数区数据映射到功能处理方法的参数上。 |
| @RequestBody |
允许request的参数在request体中,而不是在直接链接在地址的后面。 |
| @ResponseBody |
将返回值放在response体内。返回的是数据而不是页面。 |
| @Autowired |
用来装配bean,都可以写在字段上,或者方法上。byType按类型自动注入。 |
| @Resource |
用来装配bean,两个属性分别是name和type,默认byName按名称自动注入,如果使用type属性则按类型注入。 |
| @Import |
导入配置类或者导入一个带有@Component等注解要放入Spring容器中的类。 |
| @ImportResource |
加载xml配置。 |
| @SpingBootApplication |
SpringBoot的核心注解,主要目的是开启自动配置,组合了@Configurer,@EnableAutoConfiguration(核心)和@ComponentScan。可以通过@SpringBootApplication(exclude={想要关闭的自动配置的类名.class})来关闭特定的自动配置。 |
| @Configuration |
声明当前类是一个配置类(相当于一个Spring配置的xml文件)。 |
| @ConfigurationProperties |
将properties属性与一个Bean及其属性相关联,从而实现类型安全的配置。需要和@Component注解、@Configuration等结合使用。 |
| @WebAppConfiguration |
声明加载的ApplicationContext是一个WebApplicationContext。 |
| @EnableAutoConfiguration |
自动载入应用程序所需的所有Bean,组合了@Import注解,@Import注解导入了EnableAutoCofigurationImportSelector类,它扫描具有META-INF/spring.factories文件的jar包。而spring.factories里声明了有哪些自动配置。 |
| @ContextConfiguration |
加载配置ApplicationContext。 |
| @ComponentScan |
自动扫描指定包下所有使用@Service,@Component,@Controller,@Repository的类并注册。 |
| @EnableWebMvc |
开启SpringMvc的Mvc的一些默认配置:如ViewResolver,MessageConverter等。 |
| @Bean |
声明当前方法的返回值为一个Bean。@Bean(initMethod=”init”,destroyMethod=”destroy”)。 |
| @Aspect |
声明一个切面。 |
| @Before |
前置通知,在增强方法前执行。 |
| @After |
后置通知,在增强方法后执行。 |
| @Around |
环绕通知,在增强方法前和后执行。 |
| @PointCut |
声明切点,即定义拦截规则,确定有哪些方法会被切入。 |
| @Transactional |
声明事务。 |
| @Value |
读取配置文件属性,有占位符@Value("${}")和EL表达式@Value("#{}")两种方式。 |
| @PropertySource |
加载指定的配置文件。 |
| @Cacheable |
声明数据缓存。 |
| @EnableAspectJAutoProxy |
开启Spring对AspectJ的支持。 |
| @PostConstruct |
标注在方法上,该方法在构造函数执行完成之后执行。 |
| @PreDestroy |
标注在方法上,该方法在对象销毁之前执行。 |
| @Profile |
@Profile(“dev”)表示为dev时实例化。 |
| @ActiveProfiles |
用来声明活动的profile 例:@ActiveProfiles(“prod”(这个prod定义在配置类中))。 |
| @Async |
注解在方法上标示这是一个异步方法,在类上标示这个类所有的方法都是异步方法。 |
| @EnableAsync |
开启异步任务支持。注解在配置类上。 |
| @Scheduled |
注解在方法上,声明该方法是计划任务。 |
| @EnableScheduling |
注解在配置类上,开启对计划任务的支持。 |
| @Conditional |
根据满足某一特定条件创建特定的Bean。 |
| @ConditionalOnBean |
条件注解。当容器里有指定Bean的条件下。 |