properties配置文件没有加载成功

properties配置文件没有加载成功

1.需要将properties配置文件放在src目录下。
2.加载配置文件的时候,直接写文件名称,不需要写绝对路径和相对路径。

public static void init(){
        Properties properties = new Properties();
        InputStream is = BaseDao.class.getClassLoader().getResourceAsStream("datasource.properties");
        try {
            properties.load(is);
        } catch (IOException e) {
            e.printStackTrace();
        }
        driver = properties.getProperty("driver");
        url = properties.getProperty("url");
        username = properties.getProperty("username");
        password = properties.getProperty("password");
    }
发布了6 篇原创文章 · 获赞 0 · 访问量 376

猜你喜欢

转载自blog.csdn.net/weixin_45343343/article/details/101460878