Advertisement
Guest User

Untitled

a guest
Mar 26th, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. @Service
  2. public class BaseImpl implements Base{
  3. @Autowired
  4. Details details;
  5. ...
  6. public void doSomething(){
  7. }
  8. }
  9.  
  10. @Service
  11. public interface Base{
  12. void doSomething();
  13. }
  14.  
  15. @Configuration
  16. public class AppConfig {
  17. @Bean(name="samplebean")
  18. public Base getImpl(){
  19. return new BaseImpl();
  20. }
  21. }
  22.  
  23. @Repository
  24. public interface Details extends CrudRepository<..., ...>{
  25. ...
  26. }
  27.  
  28. @RestController
  29. @RequestMapping(value = "...")
  30. public class Caller{
  31. public void foo(){
  32. Base b = (Base) context.getBean("samplebean");
  33. b.doSomething();
  34. }
  35. }
  36.  
  37. Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.model.Details com.pkg.BaseImpl.details; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.model.Details] 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)}
  38. at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)
  39. at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
  40. at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
  41. ... 35 more
  42. Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.model.Details] 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)}
  43. at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1308)
  44. at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1054)
  45. at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:949)
  46. at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
  47. ... 37 more
  48.  
  49. @Configuration
  50. public class AppConfig {
  51. @Bean(name="samplebean")
  52. public Base getImpl(){
  53. return new BaseImpl();
  54. }
  55.  
  56. @Bean
  57. public Details details() {
  58. return new Details();
  59. }
  60. }
  61.  
  62. @Component
  63. public class Details {
  64. // ...
  65. }
  66.  
  67. @ComponentScan(basePackages = { "<yourBasePackage>" })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement