av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術文章
文章詳情頁

springBoot系列常用注解(小結)

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

作用是:對自定義的properties文件加載

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

springBoot系列常用注解(小結)

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

springBoot系列常用注解(小結)

亂碼解決:

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

springBoot系列常用注解(小結)

@ImportResource

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

springBoot系列常用注解(小結)

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

@Conditional

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

springBoot系列常用注解(小結)

以 HttpEncodingAutoConfiguration 自動配置類舉例

@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 這個bean則實例化創建一個,存在就不走下面的代碼

@ConditionalOnClass(CharacterEncodingFilter.class):作用是如果容器中存在CharacterEncodingFilter 這個bean(其中一個條件)則才能夠實例化者個自動配置類HttpEncodingAutoConfiguration

@ConditionalOnProperty(prefix = 'server.servlet.encoding', value = 'enabled', matchIfMissing = true)作用是如果配置文件中配置了server.servlet.encoding=enabled則才能夠實例化者這個個自動配置類HttpEncodingAutoConfiguration

springBoot中所有的自動配置類位置:

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

springBoot系列常用注解(小結)

如何判斷spring.factories這個文件中那些自動配置類是生效的?

在yml或者applicaton.properties中配置,會在控制臺打印自動配置類生效報告:

########打印自動配置類生效的報告##########debug =true

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

springBoot系列常用注解(小結)

到此這篇關于springBoot系列常用注解(小結)的文章就介紹到這了,更多相關springBoot常用注解內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Spring
相關文章:
主站蜘蛛池模板: www.99热| 国产精品99久久久久久久久久久久 | 色综合久久伊人 | 国产精品国产a级 | 久久日韩粉嫩一区二区三区 | 国产精品久久久久久妇女 | 99久久久无码国产精品 | 午夜影院在线 | 色综合视频在线 | 亚洲精品一区二区 | 91精品国产91久久综合桃花 | 亚洲国产激情 | 九九视频在线观看 | 黄色av一区 | 欧美日韩综合 | 一级a性色生活片久久毛片 一级特黄a大片 | 北条麻妃国产九九九精品小说 | 久久成人高清视频 | 久久精品中文字幕 | 中文字幕av免费 | 草草草网站 | 亚洲国产一区二区三区在线观看 | 嫩草视频入口 | 欧美精品一区二区三区在线播放 | 国产精品免费一区二区三区四区 | 国产午夜精品福利 | 成人国产在线视频 | 拍真实国产伦偷精品 | a久久久久久 | 97精品超碰一区二区三区 | av一二三区 | 欧美久久国产 | 一级欧美一级日韩片免费观看 | 国产精品欧美一区二区三区 | 国产一级精品毛片 | 久久国内精品 | 黄色一级大片在线免费看产 | 欧美日韩精品影院 | 欧美精品一区二区三区四区 在线 | 欧美一区二区三区四区五区无卡码 | 亚洲一区二区三区视频免费观看 |