Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

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

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
You're welcome
 
Paper beats rock. Scissors beats tiny ad.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic