java - How to acces jdbc properties file (for Spring security configuration) which is outside WEB-INF folder? -


how can access jdbc properties in spring security configuration outside web-inf folder of webapp ? project heirachy below

tomcat   webapps     appname        configuration          jdbc.properties          other configuration files here       webpages          jsps/htmls here       web-inf          web.xml          spring-security.xml       classes/       lib/       tlds/  

inside spring-security.xml trying refer jdbc.properties , everytime file not found exception,

    <bean class="org.springframework.beans.factory.config.propertyplaceholderconfigurer">         <property name="location" value="file:${catalina.home}/webapps/appname/configuration/jdbc.properties"/>          <property name="location" value="file:${catalina.base}/webapps/appname/configuration/jdbc.properties"/>  <property name="location" value="/configuration/jdbc.properties"/>  <property name="location" value="file:/configuration/jdbc.properties"/>  <property name="location" value="classpath:/configuration/jdbc.properties"/>  <property name="location" value="classpath:/configuration/jdbc.properties"/>  </bean>  

{catalina.home} , {catalina.base} work till server restart or application redeploy happens. answers here on or on internet point solution jdbc.properties file placed in classpath (i.e inside classes folder) can't in project due internal reasons. have spent several hours on it.

please help,

if move properties file src/main/resources, assuming project managed maven, retrieve doing

properties prop = new properties();  try {     // load properties file     prop.load(yourclass.class.getresourceasstream("/jdbc.properties")); // note leading /      system.out.println(prop.getproperty("password"));  } catch (ioexception ex) {     ex.printstacktrace(); } 

where yourclass whatever class code in.

maven places class files of compiled classes , resources in src/main/resources in web-inf/classes application can access them.

if put file in src/main/resources/somefolder, you'll need access from

prop.load(yourclass.class.getresourceasstream("/somefolder/jdbcproperties")); path provide above method relative package of class in, unless specify leading forward-slash, in case relative root of classpath, ie classes folder.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -