2013-05-11 7 views
9

का उपयोग कर Context.xml फ़ाइल में पुनर्लेखन विकल्प मेरे पास मेरे प्रोजेक्ट में Spring कॉन्फ़िगरेशन है। उस context.xml में जावा में गतिशील रूप से मेरे द्वारा लिखा गया है। मेरा सवाल यह है कि फ़ाइल को फिर से लिखने के बाद बीन्स नेमस्पेस यूआरएल क्यों नहीं आ रहा है?स्प्रिंग

मेरे context.xml पुनर्लेखन से पहले फ़ाइल:

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:util="http://www.springframework.org/schema/util" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd 
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2..xsd 
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd "> 
<!-- <context:annotation-config /> --> 

<bean class="org.springframework.ws.client.core.WebServiceTemplate" id="webServiceTemplate"> 
    <constructor-arg ref="messageFactory"/> 
    <property name="marshaller" ref="xmlbeansMarshaller"/> 
    <property name="unmarshaller" ref="xmlbeansMarshaller"/> 
    <property name="defaultUri"> 
    <value>https://google.com</value></property> 
</bean></beans> 


मेरे जावा कोड context.xml के पुनर्लेखन के लिए:

DocumentBuilderFactory docFactory1 = DocumentBuilderFactory.newInstance(); 
DocumentBuilder docBuilder1 = docFactory1.newDocumentBuilder(); 
Document doc1 = docBuilder1.parse(afilePath); 

Node incIncident1 = doc1.getElementsByTagName("beans").item(0); 

NodeList beanList = incIncident1.getChildNodes(); 

NodeList beanlist1 = beanList.item(25).getChildNodes(); 
List <Map<String, String>> aunitDetails = be.extendedData.get("uicdsDetails"); 
if (aunitDetails != null) { 
    for (int i = 0; i < aunitDetails.size(); i++) { 
     Map<String, String> unitLogDetails = aunitDetails.get(i); 
     NodeList beanList2= beanlist1.item(7).getChildNodes(); 
     if (unitLogDetails.get("uURL") != null) { 
      beanList2.item(0).setTextContent(unitLogDetails.get("uicdsURL")); 
     } else { 
      beanList2.item(0).setTextContent("https://google.com"); 
     } 
     TransformerFactory transformerFactory1 = TransformerFactory.newInstance(); 
     Transformer transformer1 = transformerFactory1.newTransformer(); 
     System.out.println(doc); 
     DOMSource source1 = new DOMSource(doc1); 
     StreamResult result1 = new StreamResult(new File(afilePath)); 
     transformer1.transform(source1, result1); 
    } 
} 


संदर्भ के बाद। एक्सएमएल फिर से लिखा है:

<?xml version="1.0" encoding="UTF-8"?> 
    <beans 
     xmlns:context="http://www.springframework.org/schema/context" 
     xmlns:util="http://www.springframework.org/schema/util" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd 
     http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2..xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd "> 
    <!-- <context:annotation-config /> --> 

    <bean class="org.springframework.ws.client.core.WebServiceTemplate" id="webServiceTemplate"> 

     <constructor-arg ref="messageFactory"/> 
     <property name="marshaller" ref="xmlbeansMarshaller"/> 
     <property name="unmarshaller" ref="xmlbeansMarshaller"/> 
     <property name="defaultUri"> 
     <value>https://google.com</value></property> 
    </bean> 

</beans> 


यहाँ फिर से लिखा context.xml फ़ाइल XML नामस्थान

xmlns="http://www.springframework.org/schema/beans" 

क्यों इस xmlns जबकि पुनर्लेखन याद आ रही है याद आ रही है?

उत्तर

3

बहुत समय पहले जब मैंने डोम के साथ खेला था, लेकिन docFactory1.setNamespaceAware(true) (यह डिफ़ॉल्ट रूप से false है) या setAttributeNS("http://www.springframework.org/schema/beans", "xmlns") का प्रयास करें।

बीटीडब्ल्यू सहायता प्राप्त करने के लिए, अपनी समस्या को कम से कम कम करने का प्रयास करें। यहां आपकी समस्या जावा डोम फ्रेमवर्क का उपयोग करने के साथ है, इसका वसंत के साथ कुछ लेना देना नहीं है। आप उस शोर को 3 लाइनों में प्रश्न पूछ सकते थे।

+0

सहायता के लिए धन्यवाद। वार्डों पर अगली बार मैं आपकी टिप्पणियों का पालन करूंगा – MadTech

+0

मुझे गलत मत समझो, दोस्त, कोई अपराध नहीं :-) 100 लाइनों के साथ कोड की 3 लाइनों के साथ समस्या को समझना हमारे लिए आसान है;] और SO में आपका स्वागत है - बीटीडब्ल्यू, क्या इन समाधानों में मदद मिली? – rlegendi

+0

@ मैडटेक: प्लस एक व्यक्ति जिसने आपकी मदद की, कृपया। – ron

1

बस जोर से सोचकर, एक आवश्यकता क्या हो सकती है जहां आप उपरोक्त कोड के साथ xml फ़ाइल को फिर से लिखेंगे।

अपने कोड को देखते हुए, ऐसा लगता है कि आप एक बीन की एक संपत्ति को अपडेट करना चाहते हैं। क्या आप बस संदर्भ से बीन प्राप्त कर सकते हैं, अपने व्यापार तर्क के आधार पर अपनी संपत्ति अपडेट कर सकते हैं और एक संदर्भ ताज़ा कर सकते हैं! इसे सरल रखना चाहिए और आपको जटिल चीज से बचा लेना चाहिए।