Hi i have configured bean:
and I want to get it in my java code. I could create a new jdbc connection but that wouldnt be efficient so I want to use my bean but I just cant get it...Code:<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource"> <property name="driverClassName" value="${database.driverClassName}"/> <property name="url" value="${database.url}"/> <property name="username" value="${database.username}"/> <property name="password" value="${database.password}"/> <property name="validationQuery" value="SELECT 1 FROM DUAL"/> <property name="testOnBorrow" value="true"/> </bean>
I am using this in my controller:
The problem is it dies like this:Code:String AppContextPath=projectDeployPath+"/WEB-INF/classes/META-INF/spring/applicationContext.xml"; ApplicationContext context=new ClassPathXmlApplicationContext("/"+AppContextPath); BasicDataSource ds=context.getBean("dataSource", BasicDataSource.class); HashMap<String, Object> map = new HashMap<String, Object>(); map.put("REPORTNAME", "Cool report"); JasperPrint jasperPrint = JasperFillManager.fillReport(JR, map,ds.getConnection());
IWell I m just having a hard time accessing the applicationContext.xml file. The funny thing is that I even had to add a "/" in front of my path passed to the constructor otherwise it wouldnt have even a start. So is there any way for me to get the actual info from the applicationContext.xml file?Code:OException parsing XML document from class path resource [/Users/kosta/Documents/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/xkosteln/WEB-INF/classes/META-INF/spring/applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [/Users/kosta/Documents/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/xkosteln/WEB-INF/classes/META-INF/spring/applicationContext.xml] cannot be opened because it does not exist
thanks


Reply With Quote
