【问题标题】:Spring Boot: "failed to scan" when spring-boot-starter-tomcat and tomcat-embed-jasper togetherSpring Boot:当 spring-boot-starter-tomcat 和 tomcat-embed-jasper 一起时“扫描失败”
【发布时间】:2021-05-02 12:04:27
【问题描述】:

我有一个 Spring Boot 应用程序。它具有以下依赖项:

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-webflux</artifactId>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>org.projectreactor</groupId>
        <artifactId>reactor-spring</artifactId>
        <version>1.0.1.RELEASE</version>
    </dependency>
</dependencies>

为了处理 HTML 页面,Spring Boot 默认使用 Thymeleaf。但是,我不喜欢 Thymeleaf 的冗长,它可能需要让输入和输出格式都是 HTML,而我根本不需要。

所以我选择使用带有 JSP 的 Spring Boot,如 here 所述。在我希望 Spring Boot/JSP 应用程序之一使用其父级的本地存储库之前,它运行良好。导致failed to scan: [cannot find some strange non-existing jar from the parent local repository in question]

事实证明,在不依赖 tomcat-embed-jasper 的情况下,failed to scan 错误消失了,父​​本地存储库被正确使用并且应用程序运行良好,但 .jsp 页面除外,它们不再是进程正如预期的那样。浏览器以原始形式获取它们。这是预期的,因为tomcat-embed-jasper 处理.jsp 文件。

所以我有两个排除选项可以防止failed to scan 错误:

  • 不要使用父级的本地存储库,因为仅包含 Jasper 就无法使用;
  • 不要使用 Spring Boot/JSP,而是使用 SpringBoot/Thymeleaf,这样我就不需要包含 Jasper。

有没有一种方法可以同时拥有有问题的 repo 和 SpringBoot/JSP?

【问题讨论】:

    标签: spring-boot jsp tomcat


    【解决方案1】:

    确实存在一些与 Jar 扫描有关的问题。我不明白细节,但无论如何,扫描可以限制 JSP/JSTL 仍然可能:见this answer

    【讨论】:

      猜你喜欢
      • 2019-08-23
      • 2016-01-29
      • 2018-11-12
      • 2020-04-05
      • 2019-10-28
      • 1970-01-01
      • 2014-01-11
      • 2019-03-14
      • 2021-07-03
      相关资源
      最近更新 更多