类路径资源[]无法解析为URL,因为它在多模块项目中不存在



我来了一个流行的错误是:class path resource [db/file.xml] cannot be resolved to URL because it does not exist.我用的是Spring Boot with version 1.3.5.RELEASE,我试着用液体碱。我的项目是多模块的。在模块A中,我有Main类,我在其中运行整个应用程序。在模块B下(从存储库根路径)B/src/main/resources/db/file.xml我有一个带有更改集的xml。在模块A中应用。我有这样的配置:

...
liquibase.change-log=classpath:db/db.changelog.project-master.xml
spring.jpa.hibernate.ddl-auto=none
spring.h2.console.enabled=true

db/db.changelog.project-master.xml

在这个文件(db.changelog.project-master.xml)下,我包含了应该包含来自另一个模块(模块B)的更改集

<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd">
<include file="db/file.xml" />

</databaseChangeLog>

我也尝试过<include file="classpath:db/file.xml" />。不幸的是,当我从模块A运行应用程序时,我得到:

Caused by: liquibase.exception.ChangeLogParseException: Error Reading Migration File: class path resource [db/file.xml] cannot be resolved to URL because it does not exist
at liquibase.parser.core.xml.XMLChangeLogSAXParser.parseToNode(XMLChangeLogSAXParser.java:112)
at liquibase.parser.core.xml.AbstractChangeLogParser.parse(AbstractChangeLogParser.java:17)
at liquibase.changelog.DatabaseChangeLog.include(DatabaseChangeLog.java:404)
at liquibase.changelog.DatabaseChangeLog.handleChildNode(DatabaseChangeLog.java:267)
... 25 more
Caused by: java.io.FileNotFoundException: class path resource [db/file.xml] cannot be resolved to URL because it does not exist

你能告诉我怎么了吗?

我不确定答案,但我认为您指定的路径"<include file="db/file.xml" />"将在"db"中搜索文件模块A的目录,将无法找到。您可以尝试为"file.xml"指定绝对路径吗?当你将它包含在主变更日志文件中时。

让我们考虑一下下面是你的项目结构:

--project
---------module A
-src
-main
- resources
- db
- db.changelog.project-master.xml
---------module B
-src
-main
- resources
- db
- file.xml

主变更日志文件将无法找到"file.xml"在"db"我认为提供file.xml的绝对路径是有帮助的。

<include file="B/src/main/db/file.xml" />

或者可以尝试提供"file.xml">

如果我对你问题的理解有误,请原谅。

干杯! !

相关内容