Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 451 Vote(s) - 3.43 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Good practice to include XML config in Java classpath?

#1
My application is configured by some Spring XML configuration files.

Is it good practice in Java to include the XML files in the classpath, and reference them in my application using the classpath?
Reply

#2
It's nice to be able to configure it both ways - either directly as a file, or via a resource on the classpath which may or may not be in a jar file. That gives you a lot of flexibility.
Reply

#3
I agree with the previous poster (+1) - have an option in case some day you will need it.
However, there is one catch. You could create yourself lots of headache if such powerful tooling will land in the wrong hands. There is no much difference between spring context files and java classes, it's a code. So, check out who are your users.. One over enthusiastic QA guru could make your life miserable if you're not prepared.
Reply

#4
I usually look in a system property first then the classpath. so:

java -DconfigFile=/filelocation/file.xml

can be read as:

String propfile = System.getProperty(configFile);
if (propfile != null) {
// read in file
new File(propfile);
...
} else {
// read in file from classpath
getClass.getResource("/configfile.xml")
}

Reply

#5
I tend to put XML config files into the classpath and expose configuration that is relevant to be adapted (e.g. for different environments) into external property files using a [`PropertyPlaceholderConfigurer`][1] or the like (depends on actual requirements).

A nice way to create profiles is to have properties files with a set of settings for each environment and let the administrator choose the one that is need by providing a system property whose value is then translated into a property file lookup. See API doc of [`PropertyPlaceholderConfigurer`][1] for details.


[1]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through