Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springBootRunner': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.pharmacy.persistence.users.dao.UserEntityDao com.pharmacy.config.SpringBootRunner.userEntityDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.pharmacy.persistence.users.dao.UserEntityDao] 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)}
- at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1202)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
- at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
- at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
- at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
- at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
- at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
- at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
- at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
- at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
- at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
- at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
- at org.springframework.boot.SpringApplication.run(SpringApplication.java:957)
- at org.springframework.boot.SpringApplication.run(SpringApplication.java:946)
- at com.pharmacy.config.SpringBootRunner.main(SpringBootRunner.java:25)
- Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.pharmacy.persistence.users.dao.UserEntityDao com.pharmacy.config.SpringBootRunner.userEntityDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.pharmacy.persistence.users.dao.UserEntityDao] 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)}
- at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)
- at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
- at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
- ... 16 common frames omitted
- Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.pharmacy.persistence.users.dao.UserEntityDao] 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)}
- at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1301)
- at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1047)
- at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)
- at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
- ... 18 common frames omitted
- package com.pharmacy.config;
- import org.springframework.boot.SpringApplication;
- import org.springframework.boot.autoconfigure.SpringBootApplication;
- import org.springframework.context.annotation.ComponentScan;
- @SpringBootApplication
- @ComponentScan("org.pharmacy")
- public class SpringBootRunner {
- public static void main(String[] args) {
- SpringApplication.run(SpringBootRunner.class, args);
- }
- }
- package com.pharmacy.persistence.users;
- import javax.persistence.Column;
- import javax.persistence.Entity;
- import javax.persistence.GeneratedValue;
- import javax.persistence.Id;
- @Entity
- public class UserEntity {
- @Id
- @GeneratedValue
- private Long id;
- @Column
- private String name;
- }
- package com.pharmacy.persistence.users.dao;
- import com.pharmacy.persistence.users.UserEntity;
- import org.springframework.data.repository.CrudRepository;
- import org.springframework.stereotype.Repository;
- @Repository
- public interface UserEntityDao extends CrudRepository<UserEntity,Long>{
- }
- package com.pharmacy.controllers;
- import com.pharmacy.persistence.users.UserEntity;
- import com.pharmacy.persistence.users.dao.UserEntityDao;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- @RestController
- public class HomeController {
- @Autowired
- UserEntityDao userEntityDao;
- @RequestMapping(value = "/")
- public String hello() {
- userEntityDao.save(new UserEntity("ac"));
- return "Test";
- }
- }
- buildscript {
- ext {
- springBootVersion = '1.2.2.RELEASE'
- }
- repositories {
- mavenCentral()
- }
- dependencies {
- classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
- }
- }
- apply plugin: 'java'
- apply plugin: 'idea'
- apply plugin: 'spring-boot'
- mainClassName = "com.pharmacy.config.SpringBootRunner"
- jar {
- baseName = 'demo'
- version = '0.0.1-SNAPSHOT'
- }
- repositories {
- mavenCentral()
- }
- dependencies {
- compile("org.springframework.boot:spring-boot-starter-data-jpa")
- compile("org.springframework.boot:spring-boot-starter-web")
- compile("org.springframework.boot:spring-boot-starter-ws")
- compile("postgresql:postgresql:9.0-801.jdbc4")
- testCompile("org.springframework.boot:spring-boot-starter-test")
- }
- spring.view.prefix: /
- spring.view.suffix: .html
- spring.jpa.database=POSTGRESQL
- spring.jpa.show-sql=false
- spring.jpa.hibernate.ddl-auto=update
- spring.datasource.driverClassName=org.postgresql.Driver
- spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
- spring.datasource.username=postgres
- spring.datasource.password=abc123
- @EnableJpaRepositories("com...jpa")
- @EntityScan("com...jpa")
- @ComponentScan("com...service")
- @ComponentScan(basePackages = {"com.pharmacy"})
- @SpringBootApplication
- @EnableAutoConfiguration
- @SpringBootApplication
- @EnableAutoConfiguration
- @ComponentScan(basePackages={"<base package name>"})
- @EnableJpaRepositories(basePackages="<repository package name>")
- @EnableTransactionManagement
- @EntityScan(basePackages="<entity package name>")
- public interface ItemRepository extends Repository {..}
- public interface ItemRepository extends Repository<Item,Long> {..}
- @Repository
- public interface UserEntityDao extends CrudRepository<UserEntity, Long>{
- }
Add Comment
Please, Sign In to add comment