-1

Unable to run springboot application due to the below error(it says, "Consider defining a bean of type 'com.example.demo.DAOinter' in your configuration". what is missing here) :-

enter image description here

Please find the details for the Service class and the DAOInter interface used for Repository annotation:-

  1. ServiceBusinessLayer class

enter image description here

  1. DAOinter class

enter image description here

When repository annotation is included in DAOinter interface, then why autowired isn't working in ServiceBusinessLayer class?

Sharing the package details and SpringBootApplication class

enter image description here

rahul soni
  • 23
  • 8
  • 1
    Share the code of SpringBootApplication class please – Beppe C Oct 15 '20 at 19:39
  • I cannot remember the exact error but it can be because of the folder structure. If you place the class with the main method in another folder/package than the parent folder/package of the classes which should serve as beans, the application would not scan all classes. The application then does not know of all the beans. Consider, to also provide your folder structure that we can have a look for this. – Felix Seifert Oct 15 '20 at 20:05
  • Make sure that DAOiniter is in the same package or a subpackage of the class annotated with `@SpringBootApplication`. This is necessary because component scanning only happens in the same package and subpackages. – Rob Winch Oct 15 '20 at 20:12
  • Maybe, [this answer](https://stackoverflow.com/a/64356596/10902231) would help. – Felix Seifert Oct 15 '20 at 20:13
  • Please share code and logs as text formatted as code, not as images. – Jens Schauder Oct 16 '20 at 05:27
  • As requested, I have shared the package and springbootapplication class details – rahul soni Oct 16 '20 at 06:06

1 Answers1

0

So, the issue was the lack of MySQL connector dependency and MySQL version in my pom.xml, due to which it was not able to connect to db and hence resulting in the above error.

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.34</version>
    </dependency>

As soon as I included this dependency, it was no longer throwing the above-mentioned error.

Also, I modified application.properties with the below-mentioned detail:-

spring.datasource.driver-class-name=com.mysql.jdbc.Driver

rahul soni
  • 23
  • 8