SpringBoot 常用注解整理备查(依据springboot的版本变化不定期更新内容)

编程知识 更新时间:2023-04-07 15:26:16

@SpringBootApplication

开启组件扫描和springBoot的自动配置,相当于@Configuration+@ComponentScan+@EnableAutoConfiguration三个注解

@Configuration

声明一个bean,可以被AnnotationConfigApplicationContext加载注册。

@ComponentScan

开启组件扫描

@Controller

MVC中的控制器,控制请求路由跳转。

@EnableAutoConfiguration

开启SpringBoot的自动配置

@RequestMapping(value = '/readingList',method=RequestMethod.GET)

可用于类上或者方法上,用于类上,表示类中的所有响应请求的方法都是以该地址作为父路径。get方法的mapping可以使用@GetMapping

@Conditional(JdbcTemplateCondition.class)

Spring 4.0引入的注解,springboot的条件化配置,只有满足xxx.class(继承Condition接口)中的条件时,才会创建这个bean

@Configuration
@EnabelConfigurationProperties(ClassC.class)
@ConditionalOnBean
@ConditionalOnClass({ClassA.class,ClassB.class})

@EnableWebSecurity

开启SpringSecurity

@Entity

标识一个JPA的实体

@Id

标识一个实体的ID

@ConfigurationProperties(prefix="amazon")

这个bean接受一个配置文件中前缀为amazon的属性,这个属性必须提供一个set方法。SpringBoot默认开启@EnableConfigurationProperties注解功能。

@Profile(“production”)

运行时,只有激活production文件,才会使用这个配置,否则忽略这个配置,可以通过设置spring.profiles.active属性激活
属性文件需遵循application-{profile}.properties这个命名规则。

其他注解:

@RunWith(SpringJunit4ClassRunner.class)

@ContextConfiguration(class=xxxConfiguration.class)

@SpringApplicationConfiguration(class=xxxConfiguration.class)

@Test

@Before

@WebIntegrationTest(value={"server.port=0"})

@WithMockUser(username="Chelsea",password="Chelsea",role="READER")

@WithUserDetails("craig")

案例实践

Maven Spring boot项目学习笔记 注解的学习:https://www.jianshu/p/49bf4944c733

 

更多推荐

SpringBoot 常用注解整理备查(依据springboot的版本变化不定期更新内容)

本文发布于:2023-04-07 15:26:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/b0e325d06577ea4f75fd52ac8e491f55.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:注解   常用   版本   内容   SpringBoot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 53729文章数
  • 14阅读数
  • 0评论数