Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Service
- public class BaseImpl implements Base{
- @Autowired
- Details details;
- ...
- public void doSomething(){
- }
- }
- @Service
- public interface Base{
- void doSomething();
- }
- @Configuration
- public class AppConfig {
- @Bean(name="samplebean")
- public Base getImpl(){
- return new BaseImpl();
- }
- }
- @Repository
- public interface Details extends CrudRepository<..., ...>{
- ...
- }
- @RestController
- @RequestMapping(value = "...")
- public class Caller{
- public void foo(){
- Base b = (Base) context.getBean("samplebean");
- b.doSomething();
- }
- }
- 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)}
- 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)
- ... 35 more
- 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)}
- at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1308)
- at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1054)
- at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:949)
- at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
- ... 37 more
- @Configuration
- public class AppConfig {
- @Bean(name="samplebean")
- public Base getImpl(){
- return new BaseImpl();
- }
- @Bean
- public Details details() {
- return new Details();
- }
- }
- @Component
- public class Details {
- // ...
- }
- @ComponentScan(basePackages = { "<yourBasePackage>" })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement