1

I am trying to optimize a massive Spring 4, Tomcat app. Startup time is about 2 mins, and I'm wondering if there is a way to exclude certain jar files from being scanned? e.g., I don't need commons-lang being scanned b/c Spring doeesn't care about that, but since you define the scanning based on context:component-scan/base-package in applicationContext.xml, i don't quite understand how I can do that. Any ideas? Maybe do something with the resource-pattern attribute?

Ron Stevenson
  • 166
  • 1
  • 13
  • AFAIK, spring doesn't scan random jars. Related doc: https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#beans-classpath-scanning –  Oct 20 '17 at 15:50
  • how does it know where to look then? Sorry, i don't know much about any of this – Ron Stevenson Oct 20 '17 at 15:56
  • org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider is used I think and with the config you tell what package should be scanned –  Oct 20 '17 at 15:58
  • what if you're using use-default-filters="true" though in context:component-scan? we seem to be using that as well as defining a ton of base packages – Ron Stevenson Oct 20 '17 at 16:37
  • ClassPathScanningCandidateComponentProvider can't know if certain JAR contains classes from the requested package or not, so it scans all JARs in the classpath by means of java.net.URLClassLoader#findResources. – Konstantin Pelepelin May 05 '18 at 11:48

1 Answers1

0

In Spring 5, one can try a new feature, which generates a list of candidates at compile time. Reference: 1.10.9. Generating an index of candidate components

Konstantin Pelepelin
  • 1,303
  • 1
  • 14
  • 29