2

I am using spring for some dependency injection via the annotations. The problem ist whenever I start the application and use the .jar ,created by gradle, in the classpath Im getting the following exception: "org.springframework.beans.factory.NoSuchBeanDefinitionException"

But if the /build/classes/main/ is in the classpath the beans are created and no exception is thrown.

So the beans are created in the build/classes/main/ but not in the build/libs/*.jar

hadamard
  • 401
  • 4
  • 16
  • 1
    Do you scan packages with `classpath:org.mypackage` or `classpath*:org.mypackage`? The last one scans jars from classpath as well. – StanislavL May 04 '17 at 09:16
  • Thank you!!! I added the @ComponentScan annotation to the spring configuration class and now it works. – hadamard May 04 '17 at 09:37

1 Answers1

4

Set @ComponentScan("classpath*:org.mypackage") to let Spring scan jars as well.

StanislavL
  • 56,971
  • 9
  • 68
  • 98