Wrote a mongodb.properties file to record the configuration information of MongoDB. Of course you can use Hibernate OGM, but there is no time. The file was placed in the/src/config/mongodb/mongodb.properties.
Several methods have been tried, and the following is possible:
Mongodb.java
...
Properties Props = new properties (); InputStream in = null; in = GetClass (). getResourceAsStream ("/config/mongodb/mongodb.properties"), try {props.load (in);} catch (IOException E ) {e.printstacktrace ();} finally {in = null;} String db = (string) props.get ("Db.url"); String port = (string) props.get ("Db.port"), This.newsdb = (string) props.get ("Newsdb"); this.gamesdb = (string) props.get ("Gamesdb");
This file will be generated to/classes/config/mongodb/mongodb.properties under Tomcat, so you can read it using the above method.
Read property file under Tomcat