java - processing xml configuration documents in spring beans -
In our application we have some static XML configurations to access routes, an example of an XML file looks like:
& lt; Configuration & gt; & Lt; Level value = "1" progress = "1" & gt; & Lt; Route destination = "one" & gt; BA & lt; / Route & gt; & Lt; / Level & gt; & Lt; Level value = "1" progress = "2" & gt; & Lt; Route destination = "one" & gt; Keba & lt; / Route & gt; & Lt; Route destination = "b" & gt; Cab & lt; / Route & gt; & Lt; / Level & gt; ..etc ... .. & lt; / Configuration & gt; On many occasions, we need to retrieve the value of the argument (s), it is argued that value , progress , And destination (all optional, all the routes should not have any argument). I know how to get it with XPath, but I would like to use it in spring bean, which
I'm thinking like something The pre-> @ service class routing configuration uses the IRouteConfiguration {document xmlRoutes = null; XPath xPath = XPathFactory.newInstance (). NewXPath (); // Constructor Public Way Configuration (try {try {DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance (); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder (); XmlRoutes = docbuilder.parse (this.getClass (). GetResourceAsStream (url)); } Catch and all ... // method public list & lt; String & gt; GetRoutes (integer level, integer progress, string destination) {string expression = string.format ("/ configuration / level [@value = '% d' and @progress = '% d'] / path [@destination = '% s '] ", Level, progress, destination); Nodelist nodelist = (nodelist) xPath.compile (expression) .evaluate (xmlRoutes, XPathConstants.NODESET); // Of course, some alternative pipelines are required to meet alternative arguments and obtain the result list. } Am I thinking that this is the right approach? I know that Spring is XML support, but as far as I can see it applies to XML (webservice) messages I am worried about issues of concurrency and possible performance? Can there be better solutions for dealing with this (I can make an Object Graph from XSD and use jxpath, or plain Java code to get the final result)?
To fully answer your question, I believe that more information will be required. "" Post-Lesson "itemprop =" text ">
" I'm thinking this is the right approach? "How many config files are there? How big is that? Do they need to be stored in XML? This is the right answer, is it hard to say without such information.
If you only approach the Spring , I recommend using InitializingBean to load your XML configuration. Here is a recent article (not mine but looks sensible)
For concurrency and performance I recommend Ga (depends on how many) that you load them all in memory using the applying bean on the startup and then your performance is fine, and the concurrency is similar to any other spring bean. < / Div>
Comments
Post a Comment