Reputation: 13
When running my SpringBoot application, I am getting this error:
@SpringBootApplication public class BootJpAexampleApplication {
public static void main(String[] args) {
ApplicationContext context=SpringApplication.run(BootJpAexampleApplication.class, args);
User_Repository userRepository = context.getBean(User_Repository.class);
User userEntity = new User();
userEntity.setNameString("Kumar ");
userEntity.setCity("RSA");
userEntity.setStatus("I m java developer..");
User save= userRepository.save(userEntity);
System.out.println(save);
}
}
I'm quite stuck on the JPA Datasource definition, because I get the following error. This is error
Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.JPA.Dao.User_Repository' available at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:341) at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:332) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1150) at com.JPA.springboot.BootJpAexampleApplication.main(BootJpAexampleApplication.java:20)
Upvotes: 0
Views: 85
Reputation: 1
i think is is because User_repository
is not annotated with @Repository
or not being scanned by Spring
please check if user_repository interface is annotated with @Repository
and its located in package which is being scanned by Spring
Use @ComponentScan
to mention the package name in which repository class exists!
Upvotes: 0