Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. @Component
  2. public interface Service {
  3. public String getConfig();
  4. }
  5.  
  6. @Service("UserService")
  7. public class userService implements Service{
  8. @Override
  9. public String getConfig() {
  10. // logic goes here
  11. return "result";
  12. }
  13. }
  14.  
  15. @Service("CustomerService")
  16. public class userService implements Service{
  17. @Override
  18. public String getConfig() {
  19. // logic goes here
  20. return "result";
  21. }
  22. }
  23.  
  24. @Configuration
  25. public class MyConfig {
  26. @Autowired
  27. ApplicationContext context;
  28. @Bean
  29. public Service getConfigBean(final String configName) {
  30. Service service = (Service) context.getBean(configName);
  31. return service;
  32. }
  33. }
  34.  
  35. @RestController
  36. @RequestMapping("/user")
  37. @Scope(value = WebApplicationContext.SCOPE_REQUEST)
  38. public class UserController {
  39. @Autowired
  40. MyConfig myConfig;
  41.  
  42. @Autowired
  43. Service service;
  44.  
  45. @RequestMapping(produces = MediaType.TEXT_HTML , method = RequestMethod.GET)
  46. public String getInitiate()
  47. {
  48. service = stateConversationConfig.getConfigBean("UserService"); // will get this String dynamically or based on logic
  49. System.out.println("service object : "+service);
  50. return "ok";
  51. }
  52. }
  53.  
  54. SEVERE: Application startup failed
  55. org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'getConfigBean' defined in class path resource [xxx/xxx/xxx/xxxxx.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [java.lang.String]: : No qualifying bean of type [java.lang.String] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [java.lang.String] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
  56. at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749)
  57. at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:464)
  58. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119)
  59. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014)
  60. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
  61. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
  62. at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
  63. at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
  64. at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
  65. at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
  66. at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
  67. at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
  68. at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
  69. at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
  70. at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
  71. at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
  72. at org.springframework.boot.SpringApplication.run(SpringApplication.java:957)
  73. at org.springframework.boot.SpringApplication.run(SpringApplication.java:946)
  74. at xx.xxx.xxxx.xxx.xxx.main(Application.java:36)
  75. Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [java.lang.String] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
  76. at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1301)
  77. at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1047)
  78. at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)
  79. at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:813)
  80. at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement