【问题标题】:want to filter scanned jars for Spring component scanning想要过滤扫描的 jar 以进行 Spring 组件扫描
【发布时间】:2018-04-01 20:08:30
【问题描述】:

我正在尝试优化大型 Spring 4 Tomcat 应用程序。启动时间约为 2 分钟,我想知道是否有办法排除某些 jar 文件被扫描?例如,我不需要扫描 commons-lang b/c Spring 并不关心这一点,但是由于您在 applicationContext.xml 中基于 context:component-scan/base-package 定义扫描,所以我不太关心了解我该怎么做。有任何想法吗?也许对资源模式属性做点什么?

【问题讨论】:

  • AFAIK,spring 不扫描随机罐子。相关文档:docs.spring.io/spring/docs/current/spring-framework-reference/…
  • 它怎么知道去哪里看呢?抱歉,我对此了解不多
  • org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider 使用我认为和配置你告诉应该扫描什么包
  • 如果您在 context:component-scan 中使用 use-default-filters="true" 会怎样?我们似乎在使用它并定义了大量的基础包
  • ClassPathScanningCandidateComponentProvider 无法知道某个 JAR 是否包含请求包中的类,因此它通过 java.net.URLClassLoader#findResources 扫描类路径中的所有 JAR。

标签: java optimization classpath spring-4 component-scan


【解决方案1】:

在 Spring 5 中,可以尝试一项新功能,该功能在编译时生成候选列表。参考:1.10.9. Generating an index of candidate components

【讨论】:

    猜你喜欢
    • 2013-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-21
    • 2015-01-13
    • 1970-01-01
    • 2015-04-25
    相关资源
    最近更新 更多