0

I have a web application that reads and writes data from/to a database using JDBC.
The SQL statements used by this application are currently injected into the data layer of the application through a XML properties file using a PropertyPlaceholderConfigurer. In this way, the SQL code and the Java code are kept separate. The DBA can edit the properties files to tune the SQL without bothering the Java developement.

(See here for an example similar to how we do this, except that we inject each individual property by @Value rather than injecting a whole Properties object).

Eventually, I will have another application that should use the same repository as the web application. To that end, I'd like to refactor the data layer into its own component. I'd like to keep the SQL in this component. (i.e., I do not want to inject the SQL statements inside of the applications configuration file).

It seems like no problem using the tag in the XML configuration and the @Rpository annotation on the class to get the bean created. And I can still inject the SQL statements into this repository class. However, to do this, the web application needs to know about and load the XML properties file from inside of the client JAR (using a "classpath:..." entry).

Is there a way to get spring to do this injection without the WAR file needing to know the name of this properties file?

Community
  • 1
  • 1
Paul Hanbury
  • 941
  • 1
  • 10
  • 24
  • AFAIK the jar generated for your dao layer can have its own spring config file where you configure the necessary beans, properties and other elements relevant to your dao layer only. Then, in your web (or any other kind of) application, you create another spring config file that imports the configuration in the dao spring file config. Not sure if this is what you're looking for. – Luiggi Mendoza Oct 22 '14 at 22:11
  • How would I reference the configuration in the JAR file? Would it be found by the component scan? Would it need to be a Java config? – Paul Hanbury Oct 23 '14 at 03:56
  • You can have component scan in both xml files and configure your beans through annotations. – Luiggi Mendoza Oct 23 '14 at 04:24

0 Answers0