日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

Spring注解@Value

發布時間:2023/11/27 生活经验 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring注解@Value 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本文參考自:?https://blog.csdn.net/ryelqy/article/details/77453713

?

@Value能讓我們在java代碼中使用property文件的屬性,使用@Value有兩種形式:

1、@Value("#{configProperties['t1.msgname']}")

2、@Value("${t1.msgname}")

?

這兩種形式,最大的區別在于配置:

1、

<bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">  <property name="locations">  <list>  <value>classpath:/config/t1.properties</value>  </list>  </property>  
</bean>

備注:configProperties是此bean的id,可自定義,并不是說一定得是configProperties

PropertiesFactoryBean 加載Properties文件的工廠類

?

2、@Value("${t1.msgname}")的配置既可以在1的基礎上擴展,也能完全自己配置

擴展方式:

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">  <property name="properties" ref="configProperties"/>  //1中bean的id
</bean>  

備注:核心是PreferencePlaceholderConfigurer 可以理解為最優先的選擇

?

自己配置:

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">  <property name="location">  <value>config/t1.properties</value>  </property>  
</bean>          

------------------------------------------------------

?

前提:

1、當前類使用@Component或由@Component擴展開來的注解,

2、xml文件內配置了是通過pakage掃描包

<context:component-scan base-package="pakage_name"/>

?

-------------------------------------------------------

?

spring boot中使用

spring boot中,我們只需要在application.properties中添加屬性即可使用,spring boot已配置好上述一切

轉載于:https://www.cnblogs.com/yanze/p/10641196.html

總結

以上是生活随笔為你收集整理的Spring注解@Value的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。