0

What are the prerequisites to auto-wired any class without implementing any interface?

Class Diagrams

  1. MainClass -> Annotation used : @SpringBootApplication @EnableTransactionalManagement

  2. DatabaseConfig -> @Configuration @EnableTransactionalManagement

  3. UserRepository -> @Repository

  4. UserService -> @Service and @Autowired UserRepository

When I am writing test class with @Autowired userRepository it is working, but when I use @Autowired UserService and trying to call userRepository methods.

I am getting this error:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: 
No qualifying bean of type [sm.services.AgendaService] found for dependency:
expected at least 1 bean which qualifies as autowire candidate for this dependency. 
Dependency annotations: {@javax.inject.Inject()}

Project Structure

Vishakha
  • 1
  • 6
  • Can you share your project/class/package structure? – Sanjay Rawat Mar 01 '16 at 20:13
  • @SanjayRawat added ! . Please check. – Vishakha Mar 01 '16 at 20:40
  • check your class sm.services.AgendaService. It seems it is missing annotation. – abinsalm Mar 01 '16 at 21:10
  • @Service public class AgendaServices, What else is required ?. I am not using any interface. – Vishakha Mar 01 '16 at 21:21
  • Is your code properly structured for AutoConfiguration? See this link - https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-structuring-your-code.html for more info. Also you can explicitly add packages to scan `@ComponentScan({"com.example.mybootapp","com.example.services","com.example.repo"})` – Sanjay Rawat Mar 02 '16 at 10:13
  • @Vishakha in case you are still looking check this answer - http://stackoverflow.com/a/35779188/5702727. I still didn't understand your project structure, thats why I didn't answer your question. If that answer doesn't solve your problem please post the structure of your app like the one in above ans. Also is this a Spring-boot app? – Sanjay Rawat Mar 04 '16 at 20:19

1 Answers1

0

I was implementing an extra interface in "public class UserService implements SomeClass", when i switch to interface to abstract class SomeClass its start working.

public class UserService extends SomeClass

Vishakha
  • 1
  • 6