I'm going over an example from the Ho Prospring3 book. It writes an app to access a function stored in the MySQL database. The app uses annotation configuration. There are only 3 lines in the xml file:
The book indicates the first line will import datasource.xml which contains the configuration to the MySQL database (which I have loaded and running with the example database). The goes on to indicate that to run this app. you need the Apache commons-dbcp.jar version 1.4. I put this dependency in my pom file and I can see commons-dbcp.1.4.jar loaded into my maven library folder. However, when I try to run the program I get the following error:
Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from relative location [dataSource-dbcp.xml]
Offending resource: class path resource [app-context-sf.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from URL [file:/D:/spring/workspace/Chp8SpringJDBCSupport/target/classes/dataSource-dbcp.xml]; nested exception is java.io.FileNotFoundException: D:\spring\workspace\Chp8SpringJDBCSupport\target\classes\dataSource-dbcp.xml (The system cannot find the file specified)
Note that D:\spring is where my workspace is located. I'm not sure what exactly is wrong here, can someone help? It's seems to be looking for dataSource-dbcp.xml, but the book makes no mention of such a file. I was under the impression having commons-dbcp.1.4.jar in my build path would take care of it.
Thanks in advance
Joined: Mar 31, 2012
Please disregard the previous post, I solved the problem. Thanks.
Could you let us know how, so that you can save anyone coming across your post the same heartache you had...
Joined: Mar 31, 2012
Sure, I'll share, even though it was a P.O.K. error (person operating keyboard) and a little embarrassing......
The line <import resource="datasource-dbcp.xml"> imports the datasource-dbcp.xml file which contains the definitions to access the database. This file is in the same directory as the xml file containing the above statement and looks like:
The last two lines define the login for the database. This file assumes the login name and password are both prospring3, which is not the case for my installation. I forgot to change the credentials. So my code was operating correctly, but I was not accessing the databbase. The example also had logging turned on so there was a ton of log statements coming out and I missed the one indicating I was not accessing the database.
I'm now on to a new example which uses java configuration to eliminate the XML file configuration. I initially got it working, but then I broke it somehow. But I'm not going to post anything until I exhaust debugging this time. Sorry to waste your time and I hope that this error does actually help someone, at least be sure you modify files correctly before you cut and paste them. I appreciate the help I have gotten on this site, I wish I could have offered some more significant solution other than a P.O.K.!
I did notice one thing about Spring. I usually backup my workspace each time I do an example. At one point I loaded the backup from when my example was working, but all my files were empty. I had to do a refresh to get them back. This seems a bit odd since the backup was just a copy of my workspace from a couple of hours previous and on the same machine. But I guess Spring keeps track of things. Once I refreshed, everything worked fine, except for the example I broke. I guess whatever I broke I saved also. So back to debugging that one.