XML file should be read and store in java object to use throughout application on spring mvc

Multi tool use
Multi tool use


XML file should be read and store in java object to use throughout application on spring mvc



I have a xml file which is having all SQL queries. While Application Context gets loaded, from the servlet, I read the file and store it in HashMap which is static and will use that object throught the application.



Now , I migrate to spring mvc . I included the sql xml in resourced folder . I need help to read and use that resource throught the application. Is there any way to handle this.



Thanks.





I don't know the structure of your file. But what I can suggest is to convert your xml file into an object UnMarshalling, then depending on your needs do whatever with that object. There are a lot of good tutorials out there.
– Dfor Tye
Jul 1 at 17:56


UnMarshalling





Thank you. I can unmarshall the object by having that logic in a class as I have this at this point of time. But I need what else needs to changed if we move to spring. Do we need to use the config class which we usually create with @configuration annotation?
– user8619805
Jul 1 at 18:01





Can I have a look at the structure of your sql xml file?
– Dfor Tye
Jul 1 at 18:24


sql xml





<sql> <db2> <query code="Filename_method""> Select * from tablename; </query> </db2> </sql>
– user8619805
Jul 1 at 18:37





I see. Just define a bean with @Component annotation. Inside it, define your your methods to retrieve and populate all your objects. Declare a @Configuration bean to define your UnMarshalling logic and Now, whenever you need that object, use @Autowired on the first class and call your methods to get your objects.
– Dfor Tye
Jul 1 at 19:05



@Component


@Configuration


UnMarshalling


@Autowired









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

lxfS2hJ1wnJ9PbIHBJ,vk4OwYbuO VrlTP2y5g,qR5gJXpsKzEidB73sUBbdmclbStZpg4sZSShi
PpDKGHMnMv5l8XoKokrclsgutPqZ OsLZNzD2je jcGS,G5a5d9hMbBvQj4BcE4yX Sp,EaMGshpwuPhm1cX961nIzM0L

Popular posts from this blog

Rothschild family

Cinema of Italy