Guest User

Untitled

a guest
Jan 10th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.93 KB | None | 0 0
  1. 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)}
  2. at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
  3. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1202)
  4. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
  5. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
  6. at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
  7. at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
  8. at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
  9. at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
  10. at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
  11. at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
  12. at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
  13. at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
  14. at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
  15. at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
  16. at org.springframework.boot.SpringApplication.run(SpringApplication.java:957)
  17. at org.springframework.boot.SpringApplication.run(SpringApplication.java:946)
  18. at com.pharmacy.config.SpringBootRunner.main(SpringBootRunner.java:25)
  19. 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)}
  20. at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)
  21. at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
  22. at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
  23. ... 16 common frames omitted
  24. 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)}
  25. at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1301)
  26. at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1047)
  27. at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)
  28. at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
  29. ... 18 common frames omitted
  30.  
  31. package com.pharmacy.config;
  32.  
  33. import org.springframework.boot.SpringApplication;
  34. import org.springframework.boot.autoconfigure.SpringBootApplication;
  35. import org.springframework.context.annotation.ComponentScan;
  36.  
  37.  
  38. @SpringBootApplication
  39. @ComponentScan("org.pharmacy")
  40. public class SpringBootRunner {
  41.  
  42.  
  43. public static void main(String[] args) {
  44. SpringApplication.run(SpringBootRunner.class, args);
  45. }
  46. }
  47.  
  48. package com.pharmacy.persistence.users;
  49.  
  50. import javax.persistence.Column;
  51. import javax.persistence.Entity;
  52. import javax.persistence.GeneratedValue;
  53. import javax.persistence.Id;
  54.  
  55.  
  56.  
  57. @Entity
  58. public class UserEntity {
  59.  
  60. @Id
  61. @GeneratedValue
  62. private Long id;
  63. @Column
  64. private String name;
  65.  
  66. }
  67.  
  68. package com.pharmacy.persistence.users.dao;
  69.  
  70. import com.pharmacy.persistence.users.UserEntity;
  71. import org.springframework.data.repository.CrudRepository;
  72. import org.springframework.stereotype.Repository;
  73.  
  74.  
  75. @Repository
  76. public interface UserEntityDao extends CrudRepository<UserEntity,Long>{
  77.  
  78. }
  79.  
  80. package com.pharmacy.controllers;
  81.  
  82. import com.pharmacy.persistence.users.UserEntity;
  83. import com.pharmacy.persistence.users.dao.UserEntityDao;
  84. import org.springframework.beans.factory.annotation.Autowired;
  85. import org.springframework.web.bind.annotation.RequestMapping;
  86. import org.springframework.web.bind.annotation.RestController;
  87.  
  88.  
  89. @RestController
  90. public class HomeController {
  91.  
  92.  
  93. @Autowired
  94. UserEntityDao userEntityDao;
  95.  
  96. @RequestMapping(value = "/")
  97. public String hello() {
  98. userEntityDao.save(new UserEntity("ac"));
  99. return "Test";
  100.  
  101. }
  102. }
  103.  
  104. buildscript {
  105. ext {
  106. springBootVersion = '1.2.2.RELEASE'
  107. }
  108. repositories {
  109. mavenCentral()
  110. }
  111. dependencies {
  112. classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
  113. }
  114. }
  115.  
  116. apply plugin: 'java'
  117. apply plugin: 'idea'
  118. apply plugin: 'spring-boot'
  119. mainClassName = "com.pharmacy.config.SpringBootRunner"
  120. jar {
  121. baseName = 'demo'
  122. version = '0.0.1-SNAPSHOT'
  123. }
  124.  
  125.  
  126. repositories {
  127. mavenCentral()
  128. }
  129.  
  130.  
  131. dependencies {
  132. compile("org.springframework.boot:spring-boot-starter-data-jpa")
  133. compile("org.springframework.boot:spring-boot-starter-web")
  134. compile("org.springframework.boot:spring-boot-starter-ws")
  135. compile("postgresql:postgresql:9.0-801.jdbc4")
  136.  
  137. testCompile("org.springframework.boot:spring-boot-starter-test")
  138. }
  139.  
  140. spring.view.prefix: /
  141. spring.view.suffix: .html
  142.  
  143. spring.jpa.database=POSTGRESQL
  144. spring.jpa.show-sql=false
  145. spring.jpa.hibernate.ddl-auto=update
  146.  
  147.  
  148. spring.datasource.driverClassName=org.postgresql.Driver
  149. spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
  150. spring.datasource.username=postgres
  151. spring.datasource.password=abc123
  152.  
  153. @EnableJpaRepositories("com...jpa")
  154. @EntityScan("com...jpa")
  155.  
  156. @ComponentScan("com...service")
  157.  
  158. @ComponentScan(basePackages = {"com.pharmacy"})
  159.  
  160. @SpringBootApplication
  161. @EnableAutoConfiguration
  162.  
  163. @SpringBootApplication
  164. @EnableAutoConfiguration
  165. @ComponentScan(basePackages={"<base package name>"})
  166. @EnableJpaRepositories(basePackages="<repository package name>")
  167. @EnableTransactionManagement
  168. @EntityScan(basePackages="<entity package name>")
  169.  
  170. public interface ItemRepository extends Repository {..}
  171.  
  172. public interface ItemRepository extends Repository<Item,Long> {..}
  173.  
  174. @Repository
  175. public interface UserEntityDao extends CrudRepository<UserEntity, Long>{
  176.  
  177. }
Add Comment
Please, Sign In to add comment