![](/img/trans.png)
[英]How do I convert a MultipartFile to a FileSystemResource
[英]How do you pass a variable into the FileSystemResource?
前言
您想出了一種方法,可以將環境變量讀取到Spring Bean中,然后“然后可以將其傳遞到FileSystemResource中”。
這里:
我可以在Spring FileSystemResource中使用基於環境變量的位置嗎?
您能否解釋一下如何將變量傳遞給FileSystemResource?
謝謝!
查理
我不喜歡這樣的單個變量具有系統屬性的想法。 很快,您可能會變成數百個可能需要設置的系統屬性。 而是像其他人建議的那樣,將屬性文件置於構建之外,並將屬性文件的位置指定為系統屬性。
在構建外部(JAR / WAR ..)的屬性文件中具有隨環境而變化的屬性,有助於進行良好的構建。
這篇博客文章可能會有所幫助。
或類似以下內容:
<bean id="myConfigPlaceholder" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" p:location="${my.sys.variable}/fooModule/foo.properties" p:placeholderPrefix="#foo{" p:placeholderSuffix="}" />
@Value("#foo{some.key.defined.in.fooPropertiesFile}")
String myFileSystemResourcePath;
(要么)
<util:properties id="fooProps" location="file:///${my.sys.variable}/fooModule.properties/>
@Value("#fooProps[some.key.defined.in.fooPropertiesFile]")
String myFileSystemResourcePath;
注意:定義property-placeholder-configurer bean時,支持不同的語法變體。 您可以選擇任何一個。 此外,而不是與@Value注射,可以參考在XML文件中的屬性與$ {} VARIABLENAME作為dlawrence建議。
對於一個項目:設置envVariable,在此示例中, my.sys.variable
可以通過以下project-->(right click)-->run as-->run as configurations-->vm arguments and there: -Dmy.sys.variable=file:///D:/myBaseDir
完成: project-->(right click)-->run as-->run as configurations-->vm arguments and there: -Dmy.sys.variable=file:///D:/myBaseDir
全球優先:
如果要在eclipse中與其他項目共享此envProp,則可以執行
Windows->Preferences->Java->Installed JREs->(select the jre)->edit->default vm arguments->and set it with something like -Dmy.sys.variable=file:///D:/myBaseDir
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.