开发者社区> 问答> 正文

SpringBoot打包之后获取配置文件内容:报错

最近在学习SpringBoot 自己写了一个名字叫boot的程序。发现如果把代码打包之后,不好获取配置文件的信息了,请问要怎么才能读取下面的etc.xml里面的信息呢 

展开
收起
kun坤 2020-06-07 13:38:36 596 0
1 条回答
写回答
取消 提交回答
  • 请参考代码:

    @Configuration
    @ImportResource({"classpath:etc.xml"})
    @PropertySource(value="classpath:log4j.properties")
    public class SpringBootTestConfiguration {
    	
    }




    ######

    打成jar包后,是不能通过new File(path)来获取文件的,需要以流的方式获取,className.class.getResourceStream("/etc.xml")来获取。

    2020-06-07 13:38:41
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
使用Spring.Initializr定制工程脚手架 立即下载
陈曦:使用Spring.Initializr定制工程脚手架 立即下载
Java Spring Boot开发实战系列课程(第17讲):Spring Boot 2.0实战Docker容器Linux 立即下载

相关实验场景

更多