Tag Archives: java.util.MissingResourceException: Can’t find bundle for base name db

[Solved] java.util.MissingResourceException: Can’t find bundle for base name db, locale zh_CN

When using bundle to load the configuration file, this error broke out:

why

The configuration file to be loaded was not found because it must be placed under the SRC directory

If you put it under the package of com.bj186.crm, you must add the package name to the pathname of the configuration file

// use bundle
    @Test
    public void test4() {
        // ResourceBundle is a tool class specifically designed to read configuration files
        // bundle can only read properties type files, only the file name is needed when reading, no suffix is needed
        // bundle also provides an iterative method to read all configurations
        ResourceBundle db = ResourceBundle.getBundle("db");
        db.getString("driver");
        Enumeration<String> keys = db.getKeys();
        while(keys.hasMoreElements()) {
            String key = keys.nextElement();
            System.out.println(key +": " + db.getString(key));
        }
    }

The solution

Move dB. Properties to SRC directory and solve the problem

In this way, the subproblem can be solved