Last active
December 21, 2015 07:48
-
-
Save bltavares/6273600 to your computer and use it in GitHub Desktop.
Follow the error: Spring Autowired and bean collectors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.example.Extractor] found for dependency [collection of com.example.Extractor]: 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:947) | |
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:774) | |
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:730) | |
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:795) | |
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:723) | |
... 33 more |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import com.example.Extractor; | |
import org.springframework.stereotype.Component; | |
import java.util.List; | |
@Component | |
public class ObjectsExtractor { | |
private final List<Extractor> comparators; | |
@Deprecated | |
private ObjectsExtractor() { | |
this.comparators = Collections.emptyList(); | |
} | |
@Autowired(required = false) | |
public ObjectsExtractor(List<ObjectComparator> comparators) { | |
this.comparators = comparators; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.example.ObjectsExtractor; | |
import org.springframework.context.support.ClassPathXmlApplicationContext; | |
public class Main { | |
public static void main(String[] args) { | |
new ClassPathXmlApplicationContext("context.xml") | |
.getBean(ObjectsExtractor.class); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.example.Extractor] found for dependency [collection of com.example.ObjectsExtractor] as autowire candidate for this dependency. Dependency annotations: {} | |
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:947) | |
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:774) | |
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:730) | |
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:795) | |
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:723) | |
... 33 more |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import com.example.Extractor; | |
import org.springframework.stereotype.Component; | |
import java.util.List; | |
@Component | |
public class ObjectsExtractor { | |
private final List<Extractor> extractor; | |
@Autowired | |
public ObjectsExtractor(List<Extractor> extractors) { | |
this.extractor = extractors; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment