Hello everyone! I hope this video has helped solve your questions and issues. This video is shared because a solution has been found for the question/problem. I create videos for questions that have solutions. If you have any other issues, feel free to reach out to me on Instagram: / ky.emrah
Below, you can find the text related to the question/problem. In the video, the question will be presented first, followed by the answers. If the video moves too fast, feel free to pause and review the answers. If you need more detailed information, you can find the necessary sources and links at the bottom of this description. I hope this video has been helpful, and even if it doesn't directly solve your problem, it will guide you to the source of the solution. I'd appreciate it if you like the video and subscribe to my channel!Get a NoSuchBeanDefinitionException in my DAO Spring + Hibernate + MySQL code
I have code based on DAO architecture with Maven on IDEA Ultimate 2024.2.2
In it, I use Spring + Hibernate to work with the MySQL database and Project Lombok to work with User entity annotations. It would seem that I set everything up according to the instructions on the Internet, but my Spring doesn’t want to start.
I'm trying to execute the following code:
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
ApplicationContext context = new AnnotationConfigApplicationContext("applicationContext.xml");
UserDaoHibernateImpl userService = context.getBean(UserDaoHibernateImpl.class);
userService.createUsersTable();
}
}
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
ApplicationContext context = new AnnotationConfigApplicationContext("applicationContext.xml");
UserDaoHibernateImpl userService = context.getBean(UserDaoHibernateImpl.class);
userService.createUsersTable();
}
}
but this code gives me the following exception:
Console:
Console:
Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'jm.task.core.jdbc.dao.UserDaoHibernateImpl' available
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:343)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:334)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1261)
at jm.task.core.jdbc.Application.main(Application.java:17)
Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'jm.task.core.jdbc.dao.UserDaoHibernateImpl' available
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:343)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:334)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1261)
at jm.task.core.jdbc.Application.main(Application.java:17)
and even if I try to execute this code from my class for tests, I get the same exception.
My project tree:
/kata_preproj_with_lombok
│ pom.xml
├── /src
│ ├── /main
│ │ ├── /java
│ │ │ ├── /jm.task.core.jdbc
│ │ │ │ ├── Application.class // this is the Main class I'm trying to run
│ │ │ │ ├── /dao
│ │ │ │ │ ├── Userdao.java
│ │ │ │ │ ├── UserDaoHibernateImpl.java
│ │ │ │ ├── /model
│ │ │ │ │ ├── User.class // entity
│ │ │ │ ├── /service // dao business logic
│ │ │ │ │ ├── UserService.class
│ │ │ │ │ ├── UserServiceImpl.class // contains UserDaoHibernateImpl methods
│ │ │ │ ├── Util // connection directory
│ │ │ │ │ ├── Util.class
│ │ ├── /resources
│ │ │ ├── database.properties // properties for connecting to the MySQL database (task requirement)
│ │ │ ├── log4j.properties // logger properties
│ │ │ ├── applicationContext.xml // Spring config with beans
├── /test
│ ├── /java
│ │ ├── UserServiceTest.java // cSource of the question:
https://stackoverflow.com/questions/7...
Question and source license information:
https://meta.stackexchange.com/help/l...
https://stackoverflow.com/