我有以下代码
public class MongoService {
private final Mongo mongo;
private static final Logger LOGGER = LoggerFactory.getLogger(MongoService.class);
public MongoService() throws UnknownHostException {
mongo = new Mongo("localhot", 2707);
DB db = mongo.getDB("contract");
LOGGER.info(db.getCollection("Test").getName());
}
public Mongo getMongoInstance() {
return mongo;
}
public void insert() {
LOGGER.info("will run mongo insert now");
}
public void query() {
LOGGER.info("will run query now");
}
public static void main(String args[]) throws UnknownHostException {
MongoService mongoService = new MongoService();
mongoService.insert();
mongoService.query();
}
}
输出
15:26:07.509 [main] INFO c.s.s.business.persist.MongoService - Test
15:26:07.514 [main] INFO c.s.s.business.persist.MongoService - will run mongo insert now
15:26:07.514 [main] INFO c.s.s.business.persist.MongoService - will run query now
主机(应该是 localhost)和端口(应该是 27017)显然是错误的,但是当我运行这个程序时,它运行并且没有给出任何异常
真的有联系吗??我确定没有,那么如何处理这种情况呢?