【问题标题】:Spring Boot 1.5.2: class path resource [] cannot be resolved to URL because it does not existSpring Boot 1.5.2:类路径资源 [] 无法解析为 URL,因为它不存在
【发布时间】:2017-04-15 17:11:07
【问题描述】:

在我的 Spring Boot 1.5.2 应用程序中,出现以下异常:

java.io.FileNotFoundException: class path resource [] cannot be resolved to URL because it does not exist

我读到如果没有标有@Entity 的类,这是Spring Boot 1.4.1 中的一个错误,但是,我使用的是较新版本,并且我也有用@Entity 注释的类,所以我真的不知道'不知道错误的原因可能是什么。

我的SpringApplication 类位于org.common.deploymentorg.common.deployment.model 中的实体,所以如果我这样注释我的SpringApplication 类,应该可以找到实体:

@SpringBootApplication
@EnableTransactionManagement
public class DeploymentBootstrapper {
  public static void main(String[] args) {
    SpringApplication.run(DeploymentBootstrapper.class, args);
  }
  ...
}

该错误仅在我在 GitLab CI 服务器上构建项目时发生,而不是在我在本地运行单元测试时发生。

【问题讨论】:

标签: java jpa spring-boot


【解决方案1】:

我不知道这是否仍然是一个话题。我遇到了几乎同样的问题。在 IDE 和开发环境中像魅力一样工作,但应用程序无法在构建系统上启动并出现上述错误。

解决方案(至少在我这边)是在 META-INF 中放置一个没有任何实体的 orm.xml。即使在类路径中有此文件,仍可以找到带注释的实体。

<?xml version="1.0" encoding="UTF-8" ?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_1.xsd"
                 version="2.1">
</entity-mappings>

【讨论】:

    猜你喜欢
    • 2016-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-26
    • 1970-01-01
    • 2017-02-19
    • 1970-01-01
    相关资源
    最近更新 更多