java - how to read multiple resources using spring annotations -
मेरे पास निम्न context.xml है।
< कोड> & lt;? Xml संस्करण = "1.0" एन्कोडिंग = "UTF-8"? & Gt; & Lt; बीन्स xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns: संदर्भ = "http: // Www.springframework.org/schema/context "xmlns: jms =" http://www.springframework.org/schema/jms "xmlns: tx =" http://www.springframework.org/schema/tx "एक्सएसआई: स्कीमा स्थान = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context Http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring- Jms-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd "& gt; & Lt; संदर्भ: एनोटेशन-कॉन्फिग / & gt; & Lt; बीन आईडी = "मायप्रॉपर्टीहॉल्डर कॉन्फिफ" वर्ग = "org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" & gt; & Lt; प्रॉपर्टी नाम = "systemPropertiesModeName" मान = "SYSTEM_PROPERTIES_MODE_OVERRIDE" / & gt; & Lt; संपत्ति नाम = "अनदेखा संसाधन नॉटफौंड" मान = "सच" / & gt; & Lt; प्रॉपर्टी नाम = "अनदेखा अपरिवर्तनीय प्लेसधारकों" मान = "सही" / & gt; & Lt; प्रॉपर्टी नाम = "स्थान" & gt; & LT; सूची & gt; & Lt;! - नोट: 'server.config.override.location' चर कन्या सर्वर की शुरुआत के दौरान सेटअप है - & gt; & LT; मूल्य & gt; फ़ाइल: # {systemProperties [ 'con.file.pathtoFile']} / myservice-service.properties & lt; / मूल्य & gt; & LT; मूल्य & gt; फ़ाइल: # {systemProperties [ 'con.file.pathtoFile']} / MyService-mynotes.txt & lt; / मूल्य & gt; & LT; मूल्य & gt; classpath: myservice-service.properties & lt; / मूल्य & gt; & LT; मूल्य & gt; classpath: MyService-mynotes.txt & lt; / मूल्य & gt; & Lt; / सूची & gt; & Lt; / संपत्ति & gt; & Lt; / सेम & gt; & Lt; / सेम & gt;
मैं निम्नलिखित में से किसी एक कुंजी के मूल्य तक पहुंचने के लिए .properties फ़ाइल से गुणों का उपयोग करने में सक्षम हूं।
@value ("$ { Myfile.path} ") निजी स्थिर स्ट्रिंग myfile.path;
लेकिन मुझे पता नहीं है कि संदर्भ से अन्य संसाधन "myservice-mynotes.txt" तक कैसे पहुंचें। असल में मैं अपने कार्यक्रम में इस "myservice-mynotes.txt" फ़ाइल का पथ प्राप्त करना चाहता हूं और फिर इसे अपने कार्यक्रम में पढ़ता हूं। उदाहरण के लिए: यहां मुझे नोट्स का उपयोग करके mynotesFilePath प्राप्त करने की आवश्यकता है और फिर पास यह स्ट्रिंग एक विधि है जो फ़ाइल के पथ को स्वीकार करता है।
माइर्नोट्सफ़ाइलपैथ = "C: /test/myservice-mynotes.txt";
और फिर
फ़ाइल f = नया फ़ाइल (mynotesFilePath);
कृपया मदद करें।
मुझे लगता है कि वहाँ कुछ है भ्रम यहाँ।
सम्पत्ति प्रदाताधारक कॉन्फ़िग्युरर आपकी बीन्स को गुणों को पढ़ता और प्रचार करता है।
यदि आपको संपत्तियों और मूल्यों की ज़रूरत नहीं है, लेकिन इसके बजाय कुछ फ़ाइल स्थान प्राप्त करना चाहते हैं, तो आप संसाधन के बारे में बात कर रहे हैं, जो हो सकता है संदर्भ का उपयोग करके प्राप्त, देखें:
Comments
Post a Comment