【问题标题】:How to deaI with JAR scanning in my spring boot app when I have "Failed to scan[...]" warnings?当我有“无法扫描 [...]”警告时,如何在我的 Spring Boot 应用程序中处理 JAR 扫描?
【发布时间】:2019-10-18 23:37:38
【问题描述】:

当我使用 java 11 而不是 java 8 时,我收到了一些警告消息,因为一些新的依赖项(jaxb、jaxws)。 消息是:

WARN  o.a.t.u.s.StandardJarScanner.log - Failed to scan [...] from classloader hierarchy

对于很多 JAR(一些示例:jaxb-api.jar、txw2-2.4.0-b180830.0438.jar、istack-commons-runtime-3.0.7.jar...)

所以为了解决这个问题,我可以添加到我的 @Configuration 文件中

@Bean
      public TomcatServletWebServerFactory tomcatFactory() {
        return new TomcatServletWebServerFactory() {
          @Override
          protected void postProcessContext(Context context) {
            ((StandardJarScanner) context.getJarScanner()).setScanManifest(false);
          }
        };
      }

跳过对所有 JAR 的 JAR 扫描。

所以我的问题是,这个 JAR 扫描是什么,我需要它吗? 另外,我知道我可以为 tomcat.util.scan.StandardJarScanFilter.jarsToSkip 添加 jar 到 catalina.properties,但我可以在我的 Spring Boot 应用程序中执行此操作吗?

【问题讨论】:

    标签: java spring-boot tomcat


    【解决方案1】:

    所以我仍然不知道 JAR 扫描的用途,但我找到了一种方法来排除某些与 jaxb 相关的包。 将此添加到@Configuration 文件中

    @Bean
        public TomcatServletWebServerFactory tomcatFactory() {
            return new TomcatServletWebServerFactory() {
                @Override
                protected void postProcessContext(Context context) {
                    Set<String> pattern = new LinkedHashSet<>();
    
                    pattern.add("jaxb*.jar");
                    pattern.add("jaxws*.jar");          
    
                    StandardJarScanFilter filter = new StandardJarScanFilter();
                    filter.setTldSkip(StringUtils.collectionToCommaDelimitedString(pattern));
    
                    ((StandardJarScanner) context.getJarScanner()).setJarScanFilter(filter);
    
                }
            };
        }
    

    【讨论】:

      【解决方案2】:

      请参阅 Sundararaj Govindasamy 和 rustyx 的答案: AFTER upgrade from Spring boot 1.2 to 1.5.2, FileNotFoundException during Tomcat 8.5 Startup

      例如在application.properties:

      server.tomcat.additional-tld-skip-patterns= # Comma-separated list of additional patterns that match jars to ignore for TLD scanning.
      

      (https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html)

      您应该只列出有问题的罐子,例如使用 *.jar 将破坏 JSP/JSTL 支持。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-01-06
        • 2020-12-03
        • 2012-09-03
        • 1970-01-01
        • 1970-01-01
        • 2014-10-08
        • 1970-01-01
        • 2015-04-25
        相关资源
        最近更新 更多