Heroku Unable To Find XML Config File

前端 未结 2 399
既然无缘
既然无缘 2021-01-15 22:08

I uploaded a Spring application to Heroku but the application crashed with the following error:

java.io.FileNotFoundException: class path resource [com/myname/

2条回答
  •  臣服心动
    2021-01-15 22:31

    I suspect that when you are running locally, it is picking up the file on the classpath as a regular file on the filesystem (i.e. not inside of a JAR).

    On Heroku, it is probably inside of a JAR file, which means it is not a regular file, and must be read as an input stream, which might look like this:

    ClassLoader cl = this.getClass().getClassLoader();
    InputStream inputStream = cl.getResourceAsStream("com/myname/myapp/config/dao-context.xml");
    

    You can probably reproduce the problem locally by running the same command that's in your Procfile.

    If this is not the case, then make sure the file exists on Heroku by running this command:

    $ heroku run ls com/myname/myapp/config/dao-context.xml
    

提交回复
热议问题