17

I have 2 projects. One is a DAL project that does CRUD operations on a neo4j DB using spring neo4j APIs . This project is packaged as a jar and included in project #2. Project #2 Is a Spring restful services project that uses spring boot to package and create an executable jar that runes on an embedded tomcat server.

When trying to run my executable jar that Spring boot has created for me I keep getting this exception. expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

Based off of my reading if I am using @ComponentScan I can give the annotation directories to look in. So I give it the base dir for my services project. And I give it the base dir for my included DAL.jar but still no luck here is what the annotation looks like.

Extracted from comments:

Component scan declaration

@ComponentScan({"com.foo.dal.*","com.foo.notification.*"})

Stacktrace:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pushCommandsController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.teradata.dal.example.PushRepository com.teradata.notification.rest.controller.PushCommandsController.repository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.teradata.dal.example.PushRepository] found for dependency:
expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

UPDATE:

based off of @chrylis answer: Made change to @ComponenetScan

@ComponentScan({"com.teradata.notification","com.teradata.dal"})

running in to:

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
at java.lang.Thread.run(Thread.java:744)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.boot.autoconfigure.MessageSourceAutoConfiguration' is defined

MORE DETAIL ON THE DAL PROJECT AND THE SERVICE PROJECT:

DAL PROJECT:

DAL project structure


DAL classes


DAL classes


DAL classes


DAL classes


Services Project:

Service project structure


Service classes


Service classes


Service classes

Muhi Masoud
  • 207
  • 1
  • 3
  • 7
  • Sorry forgot the annotation that I am using – Muhi Masoud Mar 16 '14 at 20:51
  • @ComponentScan({"com.foo.dal.*","com.foo.notification.*"}) – Muhi Masoud Mar 16 '14 at 20:51
  • Don't use "thanks" and please attach code sample. As well as exception thrown. – Paweł Dyda Mar 16 '14 at 21:08
  • I included the relevant part of the stack trace but here is the full print out. – Muhi Masoud Mar 16 '14 at 21:40
  • Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pushCommandsController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.teradata.dal.example.PushRepository com.teradata.notification.rest.controller.PushCommandsController.repository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.teradata.dal.example.PushRepository] found for dependency: – Muhi Masoud Mar 16 '14 at 21:46
  • 1
    expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} – Muhi Masoud Mar 16 '14 at 21:46
  • com.teradata.notification.rest.controller.PushCommandsController is not component scanned? But it looks like this class is not even a class of your library. – Sinisha Mihajlovski Mar 17 '14 at 09:12
  • sinisa229 yes sorry in my example I used foo and not the package name and did't change it in the stack trace. some what new to posting on stack. – Muhi Masoud Mar 17 '14 at 13:24
  • 2
    More detail is good, but always post text like the contents of your images as text. Images are difficult to read and can't be searched or copied for testing. – chrylis -cautiouslyoptimistic- Mar 21 '14 at 14:48

2 Answers2

19

The argument to @ComponentScan is a package name, and those strings aren't valid packages. Drop the .* from them; Spring scans subpackages automatically.

chrylis -cautiouslyoptimistic-
  • 75,269
  • 21
  • 115
  • 152
2

Had this same issue for a short while, then @EntityScan did the trick for me, just as adviced here - Spring Boot w/ JPA: move @Entity to different package.

Hope that helps

Community
  • 1
  • 1
Tomek Samcik
  • 526
  • 4
  • 7