【springssm加载applicationContext.xml文件的一个坑】

1、文件的位置:

      resource/spring/ApplicationContext.xml

2、使用FileSystemXmlApplicationContext读取文件

        String path = this.getClass().getClassLoader().getResource("").getPath();
        String filepath = "file:"+ path + "spring/ApplicationContext.xml";
        applicationContext = new FileSystemXmlApplicationContext(filepath);

3、获取类

      ObsMapper obsMapper = applicationContext.getBean(ObsMapper.class);

参考文档:

https://blog.csdn.net/xxxknight/article/details/46671355

猜你喜欢

转载自my.oschina.net/maojindaoGG/blog/1811630