当我“无法扫描 [...]"时,如何在 Spring Boot 应用程序中处理 JAR 扫描?警告? [英] How to deaI with JAR scanning in my spring boot app when I have "Failed to scan[...]" warnings?

查看:31
本文介绍了当我“无法扫描 [...]"时,如何在 Spring Boot 应用程序中处理 JAR 扫描?警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have some warning messages when I use java 11 instead of java 8 because some of some new dependecies (jaxb, jaxws). The message is :

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...)

For a lot of JAR (some examples: jaxb-api.jar, txw2-2.4.0-b180830.0438.jar, istack-commons-runtime-3.0.7.jar...)

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

So to solve this I can add to my @Configuration file

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

跳过所有 JAR 的 JAR 扫描.

Which skip the JAR scaning for all JAR.

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

So my question is, what is this JAR scaning and do I need it? Also, I know I can add jar to catalina.properties for tomcat.util.scan.StandardJarScanFilter.jarsToSkip but can I do this in my spring boot app?

推荐答案

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

So I still don't know the use of the JAR scanning but I've found a way to just exclude certain jaxb related packages. Add this to the @Configuration file

@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);

            }
        };
    }

这篇关于当我“无法扫描 [...]"时,如何在 Spring Boot 应用程序中处理 JAR 扫描?警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆