亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

springBoot系列常用注解(小結(jié))

瀏覽:3日期:2023-03-17 11:28:23
@PropertySource

作用是:對(duì)自定義的properties文件加載

使用:@PropertySource(value={'classpath:people.properties'})或者@PropertySource(value='classpath:people.properties')

springBoot系列常用注解(小結(jié))

properties文件,獲取到值亂碼問題

springBoot系列常用注解(小結(jié))

亂碼解決:

file ->settings -->file encoding--> 勾選Transparent native-to-ascill conversion

springBoot系列常用注解(小結(jié))

@ImportResource

作用:可以讓spring的配置文件生效

springBoot系列常用注解(小結(jié))

使用:在啟用類上加ImportResource注解,如@ImportResource(value = 'classpath:person.xml')或者@ImportResource(locations ={'classpath:person.xml'})

@Conditional

作用:必須是@Conditional指定的條件成立,才給容器中添加組件或者是讓自動(dòng)配置類生效。

springBoot系列常用注解(小結(jié))

以 HttpEncodingAutoConfiguration 自動(dòng)配置類舉例

@Configuration(proxyBeanMethods = false)@EnableConfigurationProperties(ServerProperties.class)@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)@ConditionalOnClass(CharacterEncodingFilter.class)@ConditionalOnProperty(prefix = 'server.servlet.encoding', value = 'enabled', matchIfMissing = true)public class HttpEncodingAutoConfiguration { private final Encoding properties; public HttpEncodingAutoConfiguration(ServerProperties properties) {this.properties = properties.getServlet().getEncoding();} @Bean@ConditionalOnMissingBeanpublic CharacterEncodingFilter characterEncodingFilter() {CharacterEncodingFilter filter = new OrderedCharacterEncodingFilter();filter.setEncoding(this.properties.getCharset().name());filter.setForceRequestEncoding(this.properties.shouldForce(Encoding.Type.REQUEST));filter.setForceResponseEncoding(this.properties.shouldForce(Encoding.Type.RESPONSE));return filter;}

@ConditionalOnMissingBean:作用是如果容器中不存在CharacterEncodingFilter 這個(gè)bean則實(shí)例化創(chuàng)建一個(gè),存在就不走下面的代碼

@ConditionalOnClass(CharacterEncodingFilter.class):作用是如果容器中存在CharacterEncodingFilter 這個(gè)bean(其中一個(gè)條件)則才能夠?qū)嵗邆€(gè)自動(dòng)配置類HttpEncodingAutoConfiguration

@ConditionalOnProperty(prefix = 'server.servlet.encoding', value = 'enabled', matchIfMissing = true)作用是如果配置文件中配置了server.servlet.encoding=enabled則才能夠?qū)嵗哌@個(gè)個(gè)自動(dòng)配置類HttpEncodingAutoConfiguration

springBoot中所有的自動(dòng)配置類位置:

orgspringframeworkbootspring-boot-autoconfigure2.4.5spring-boot-autoconfigure-2.4.5.jar!META-INFspring.factories文件中

springBoot系列常用注解(小結(jié))

如何判斷spring.factories這個(gè)文件中那些自動(dòng)配置類是生效的?

在yml或者applicaton.properties中配置,會(huì)在控制臺(tái)打印自動(dòng)配置類生效報(bào)告:

########打印自動(dòng)配置類生效的報(bào)告##########debug =true

其中:Negative match:表示未生效;Positive match:表示生效的

springBoot系列常用注解(小結(jié))

到此這篇關(guān)于springBoot系列常用注解(小結(jié))的文章就介紹到這了,更多相關(guān)springBoot常用注解內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 在线观看二区三区午夜 | 国产日韩免费 | 久草视频中文在线 | 国产精品美女福利视频一区 | 成人免费视频在线看 | 最新内地三级在线观看 | 日本视频高清免费观看xxx | 爱爱男女在线观看视频高清 | 猫咪视频成人永久免费观看 | 精品国产综合区久久久久99 | 欧美日韩一区二区中文字幕视频 | 黄色片一 | 亚洲黄色a级片 | 香蕉福利| 亚洲精品国产成人专区 | 亚洲视频在线免费 | 黄色网址网站在线观看 | 综合免费视频 | 大桥未久日韩欧美亚洲国产 | 国内精品自在自线2020 | 精品午夜久久影视 | 亚洲视频在线不卡 | 毛片免费全部完整播放 | 日韩岛国片 | 日韩在线精品 | 久久久久国产精品免费网站 | sese在线| 综合久久综合久久 | 欧美日韩乱码毛片免费观看 | 欧美福利一区二区三区 | 免费高清成人啪啪网站 | 亚洲日韩欧美综合 | 欧美yw193.c㎝在线观看 | 成人欧美一级毛片免费观看 | 精品理论片一区二区三区 | 成年视频xxxxxx在线 | 成人无遮挡免费网站视频在线观看 | 亚洲精品一区vv国产 | 久久久久久久久久综合情日本 | 欧美日韩成人午夜免费 | 小视频在线免费观看 |