日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
SpringBoot這些常用注解你該知道

@SpringBootApplication

這是 Spring Boot 最最最核心的注解,用在 Spring Boot 主類上,標識這是一個 Spring Boot 應(yīng)用,用來開啟 Spring Boot 的各項能力。

十余年的白河網(wǎng)站建設(shè)經(jīng)驗,針對設(shè)計、前端、開發(fā)、售后、文案、推廣等六對一服務(wù),響應(yīng)快,48小時及時工作處理。網(wǎng)絡(luò)營銷推廣的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動調(diào)整白河建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計,從而大程度地提升瀏覽體驗。成都創(chuàng)新互聯(lián)公司從事“白河網(wǎng)站設(shè)計”,“白河網(wǎng)站推廣”以來,每個客戶項目都認真落實執(zhí)行。

 
 
 
  1. @SpringBootApplication 
  2. public class BaseWebApplication extends SpringBootServletInitializer { 
  3.  
  4.     @Override 
  5.     protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { 
  6.         return builder.sources(BaseWebApplication.class); 
  7.     } 
  8.  
  9.     public static void main(String[] args) { 
  10.         SpringApplication.run(BaseWebApplication.class, args); 
  11.     } 

@EnableAutoConfiguration

開啟自動配置注解,SpringBoot 就能根據(jù)當前類路徑下的包或者類來配置 Bean。

 
 
 
  1. @Target(ElementType.TYPE) 
  2. @Retention(RetentionPolicy.RUNTIME) 
  3. @Documented 
  4. @Inherited 
  5. @SpringBootConfiguration 
  6. @EnableAutoConfiguration 
  7. @ComponentScan(excludeFilters = { @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class), 
  8.         @Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) }) 
  9. public @interface SpringBootApplication { 
  10. }   

 @Configuration

這是 Spring 3.0 添加的一個注解,用來代替 applicationContext.xml 配置文件,通過注解來配置Bean。

 
 
 
  1. @Configuration 
  2. public class WebConfig implements WebMvcConfigurer { 
  3. }   

 @ComponentScan

這是 Spring 3.1 添加的一個注解,用來代替配置文件中的 component-scan 配置,開啟組件掃描,即自動掃描包路徑下的 @Component 注解進行注冊 bean 實例到 context 中。

 
 
 
  1. @ComponentScan(basePackages = {"com.pack.a", "com.jack.b"}) 
  2. public class SqlSessionFactoryConfig { 

 @Conditional

這是 Spring 4.0 添加的新注解,用來標識一個 Spring Bean 或者 Configuration 配置文件,當滿足指定的條件才開啟配置。

 
 
 
  1. @Bean 
  2. @Conditional({SEEConditional.class}) 
  3. public ServerEndpointExporter serverEndpointExporter (){   
  4.   return new ServerEndpointExporter();   
  5. public class SEEConditional implements Condition { 
  6.  
  7.     @Override 
  8.     public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { 
  9.         String active = context.getEnvironment().getProperty("app.profiles.active") ; 
  10.         return !"prod".equals(active) ; 
  11.     } 
  12.  

 @ConditionalOnBean

當容器中有指定的 Bean 才開啟配置。

@ConditionalOnMissingBean

當容器中沒有指定的 Bean 才開啟配置。

 
 
 
  1. @ConditionalOnMissingBean({ DataSource.class, XADataSource.class }) 
  2. protected static class EmbeddedConfiguration { 

 @ConditionalOnClass

組合 @Conditional 注解,當容器中有指定的 Class 才開啟配置。

 
 
 
  1. @ConditionalOnClass({ RabbitTemplate.class, Channel.class }) 
  2. public class RabbitAutoConfiguration { 
  3. }   

 @ConditionalOnMissingClass

當容器中沒有指定的 Class 才開啟配置。

@ConditionalOnWebApplication

當前項目類型是 WEB 項目才開啟配置。

當前項目有以下 3 種類型。

 
 
 
  1. /** 
  2.  * Any web application will match. 
  3.  */ 
  4. ANY, 
  5. /** 
  6.  * Only servlet-based web application will match. 
  7.  */ 
  8. SERVLET, 
  9. /** 
  10.  * Only reactive-based web application will match. 
  11.  */ 
  12. REACTIVE 

 @ConditionalOnNotWebApplication

當前項目類型不是 WEB 項目才開啟配置。

@ConditionalOnProperty

當指定的屬性有指定的值時才開啟配置。

 
 
 
  1. @Bean 
  2. @ConditionalOnProperty(prefix = "spring.rabbitmq", name = "dynamic", matchIfMissing = true) 
  3. public AmqpAdmin amqpAdmin(ConnectionFactory connectionFactory) { 
  4.   return new RabbitAdmin(connectionFactory); 

 @ConditionalOnExpression

當 SpEL 表達式為 true 時才開啟配置。

@ConditionalOnJava

當運行的 Java JVM 在指定的版本范圍時才開啟配置。

@ConditionalOnResource

當類路徑下有指定的資源才開啟配置。

@ConditionalOnJndi

當指定的 JNDI 存在時才開啟配置。

@ConditionalOnSingleCandidate

當指定的 class 在容器中只有一個 Bean,或者同時有多個但為首選時才開啟配置。

@ConfigurationProperties

用來加載額外的配置(如 .properties 文件),可用在 @Configuration 注解類,或者 @Bean 注解方法上面。

 
 
 
  1. @Bean 
  2. @ConfigurationProperties(prefix = DataSourceProperties.PREFIX) 
  3. public DataSource dataSource() { 
  4.      DataSourceBuilder factory = DataSourceBuilder 
  5.                     .create(this.properties.getClassLoader()) 
  6.                     .driverClassName(this.properties.getDriverClassName()) 
  7.                     .url(this.properties.getUrl()).username(this.properties.getUsername()) 
  8.                     .password(this.properties.getPassword()); 
  9.             if (this.properties.getType() != null) { 
  10.                 factory.type(this.properties.getType()); 
  11.             } 
  12.             return factory.build(); 

 @EnableConfigurationProperties

配合 @ConfigurationProperties 注解使用,用來開啟對 @ConfigurationProperties 注解配置 Bean 的支持。

 
 
 
  1. @Configuration 
  2. @ConditionalOnClass({ DataSource.class, EmbeddedDatabaseType.class }) 
  3. @EnableConfigurationProperties(DataSourceProperties.class) 
  4. public class DataSourceAutoConfiguration { 
  5. }   

 @AutoConfigureAfter

用在自動配置類上面,表示該自動配置類需要在另外指定的自動配置類配置完之后。

如 Mybatis 的自動配置類,需要在數(shù)據(jù)源自動配置類之后。

 
 
 
  1. @AutoConfigureAfter({ DataSourceAutoConfiguration.class, MybatisLanguageDriverAutoConfiguration.class }) 
  2. public class MybatisAutoConfiguration implements InitializingBean { 
  3. }   

 @AutoConfigureBefore

表示該自動配置類需要在另外指定的自動配置類配置之前。

@Import

這是 Spring 3.0 添加的新注解,用來導(dǎo)入一個或者多個 @Configuration 注解修飾的類,這在 SpringBoot 里面應(yīng)用很多。

 
 
 
  1. @Import(CachingConfigurationSelector.class) 
  2. public @interface EnableCaching { 
  3. }   

 @ImportResource

這是 Spring 3.0 添加的新注解,用來導(dǎo)入一個或者多個 Spring 配置文件,這對 Spring Boot 兼容老項目非常有用,因為有些配置無法通過 Java Config 的形式來配置就只能用這個注解來導(dǎo)入。

 
 
 
  1. @ImportResource({ "classpath:spring/application-*.xml" }) 
  2. @SpringBootApplication 
  3. public class AppApplication { 
  4. }   

 @RestController

該注解是@ResponseBody + @Controller的組合。返回的內(nèi)容是return 的內(nèi)容,無法返回jsp或html頁面等視圖文件。

 
 
 
  1. @RestController 
  2. @RequestMapping("/users") 
  3. public class UsersController { 
  4. }   

 @RequestMapping

映射請求路徑。

@GetMapping

映射Get請求

@PostMapping

映射post請求

@PatchMapping

映射method為patch的請求。一般用于個別屬性的修改操作

@PutMapping

創(chuàng)建新的資源或替換請求負載目標資源的表示。Put冪等,POST不是

@DeleteMapping

刪除資源

@RequestBody

指示接口參數(shù)接受的是該請求的主體內(nèi)容。

@PathVariable

接受請求路徑中的占位符的值。


本文題目:SpringBoot這些常用注解你該知道
本文鏈接:http://www.5511xx.com/article/cdhcdhd.html