• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Load and Inject to a Property from XML Property File with Spring

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I am trying to load SQL queries from an XML property file and inject it as a java.util.Property into my DAO class. The SQLs.xml resides in the same directory as the application context (I'm using Maven structure, so they all under src/main/resources). My application context file looks like following:


And the SQLs.xml content is:


The DAO class:


I am loading the context file in the Main application with:

I can load the EmployeeDAO without an issue and call on its getEmployee() method. Even the datasource pulls all the needed key/values without an issue. But the queryProps is always null.
 
Ranch Hand
Posts: 375
1
Python Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You've 2 different instances of EmployeeDAO there. In one of them you're injecting dataSource, and in the other one, queryProps. So, for both the instances, one of the Properties references will be null. I suspect you're getting the 1st instance, that is why you're getting queryProps as null.
You need to inject both the properties in the same instance.
 
Favil Von
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

R. Jain wrote:You've 2 different instances of EmployeeDAO there. In one of them you're injecting dataSource, and in the other one, queryProps. So, for both the instances, one of the Properties references will be null. I suspect you're getting the 1st instance, that is why you're getting queryProps as null.
You need to inject both the properties in the same instance.



You're right. I injected both into a single instance of my DAO class and the Property seems to be populated accordingly. Thank you.

 
R. Jain
Ranch Hand
Posts: 375
1
Python Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome
 
You'll never get away with this you overconfident blob! The most you will ever get is this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic