Config. xnl at first, the document path is in src/Dao/config. xml
In the basedao class under the DaO directory, parsing the config. xml file path = "/Dao/config. xml" seems to be normal. If you can run tomcat, an error is always reported. The system cannot find the specified file path.
I put it under the root directory of SRC/Web-Info and other files, and the system still shows that the specified file path cannot be found. Baidu times, after all the suggestions are invalid, it takes two hours to debug and summarize the two methods.
First, you can directly request the server resources through the URL, so you can put the config. xml file under the web root directory, and then pass the URL path to the parser, as shown in the following figure:
PrivateString Config = "http: // localhost: 8081/ch06/config. xml ";
The protocol and port number can be obtained through this method.
String Path =Request. getcontextpath (); string basepath= Request. getscheme () + ": //" + request. getservername () + ":" + request. getserverport () + path + "/";
But dependent on the request, it looks awkward.
Second: Later I remembered why the path of the configuration file loaded in hibernate was so dry. I found the configuration. Class file in the hibernate3 package and opened it with The Decompilation software,
I found that I/O streams were used to load path resources. After some deliberation, I finally got it done. The path is still the path above. The code in the basedao class is as follows:
PrivateInputstream Config =This. Getclass (). getresourceasstream ("/Dao/config. xml"); Parser. parse (config, GH );
Run Tomcat again to get the result.