Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Component
- public interface Service {
- public String getConfig();
- }
- @Service("UserService")
- public class userService implements Service{
- @Override
- public String getConfig() {
- // logic goes here
- return "result";
- }
- }
- @Service("CustomerService")
- public class userService implements Service{
- @Override
- public String getConfig() {
- // logic goes here
- return "result";
- }
- }
- @Configuration
- public class MyConfig {
- @Autowired
- ApplicationContext context;
- @Bean
- public Service getConfigBean(final String configName) {
- Service service = (Service) context.getBean(configName);
- return service;
- }
- }
- @RestController
- @RequestMapping("/user")
- @Scope(value = WebApplicationContext.SCOPE_REQUEST)
- public class UserController {
- @Autowired
- MyConfig myConfig;
- @Autowired
- Service service;
- @RequestMapping(produces = MediaType.TEXT_HTML , method = RequestMethod.GET)
- public String getInitiate()
- {
- service = stateConversationConfig.getConfigBean("UserService"); // will get this String dynamically or based on logic
- System.out.println("service object : "+service);
- return "ok";
- }
- }
- SEVERE: Application startup failed
- 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: {}
- at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749)
- at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:464)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
- 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 xx.xxx.xxxx.xxx.xxx.main(Application.java:36)
- 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: {}
- 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.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:813)
- at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement