mybatis配置文件找不到,但是jar包里有

Mybatis打包之后明显是有mybatis-config.xml的配置文件,但是就是死活找不到,提示

是怎么回事啊,网上的答案都是解决没有xml没有打包进jar包里的

从上面可以看出来,jar包里是有mybatis-config.xml的,而且也编译了

这是我的Mybatis工具类

public class MybatisUtils {

    private static SqlSessionFactory sqlSessionFactory;

    static {
        String resource = "mybatis-config.xml";
        Properties properties = new Properties();
        properties.setProperty("username", Pharmacist.getInstance().getConfig().getString("database.username"));
        properties.setProperty("password", Pharmacist.getInstance().getConfig().getString("database.password"));
        String port = Pharmacist.getInstance().getConfig().getString("database.port");
        String database = Pharmacist.getInstance().getConfig().getString("database.name");
        String host = Pharmacist.getInstance().getConfig().getString("database.host");
        String url = "jdbc:mysql://" + host + ":" + port + "/" + database + "?useSSL=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC";
        properties.setProperty("url", url);
        InputStream inputStream = null;
        try {
            inputStream = Resources.getResourceAsStream(resource);
        } catch (IOException e) {
            e.printStackTrace();
        }
        sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream, properties);
    }

    public static SqlSession getSqlSession() {
        return sqlSessionFactory.openSession(true);
    }
}

我的resources文件夹

求大佬解答,谢谢谢谢!

查看全部
wisdommee
wisdommee
2020/11/25 08:55
  • maven
  • jar
  • mysql
  • intellij-idea
  • java-ee
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

3个回复