参考资料:spring4.x企业应用开发实践

按照书本中调用资源的时候,使用

1.直接通过接口

Resource res = new ClassPathResource("xxxxxxx");

2.通过资源加载器

ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource res = resolver.getResource("xxxxxxxx");

3.通过beanfactory和applicationcontext

ApplicationContext ctx =
        new ClassPathXmlApplicationContext("xxxxxxxx");

都会出现无法找到对应资源的问题(只针对xml配置文件):

spring在idea中xml的路径问题

 

通过以上信息可以判断出问题在意找不到对应的xml配置文件。

问题出现在,编译完之后的target目标文件路径下没有xml文件

spring在idea中xml的路径问题

 

问题在于,idea默认不会把.java下的xml配置文件转移到生成的target中。

解决方法:

1.把生成target放到.java里,这样就能读取到xml了,具体参考https://blog.csdn.net/baidu_32045201/article/details/78386058

2.把xml专门声明编译到target中 具体参考https://blog.csdn.net/qq_38196449/article/details/78757752

3.把配置文件放到resources目录下,idea会自动编译到target中。

 

实际操作采用了3.

相关文章:

  • 2021-10-23
  • 2022-12-23
  • 2021-06-09
  • 2022-12-23
  • 2021-06-03
  • 2022-12-23
  • 2021-11-28
  • 2021-11-28
猜你喜欢
  • 2021-07-24
  • 2021-06-14
  • 2021-04-04
  • 2022-12-23
  • 2022-03-08
  • 2021-04-15
  • 2022-12-23
相关资源
相似解决方案