Announcement Announcement Module
Collapse
No announcement yet.
Possible to @Inject a List of entities? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Possible to @Inject a List of entities?

    I have the following @Configuration class which defines an @Bean as a List<IndexClass> type. IndexClass is an entity type. The configuration itself seems to take place just fine. However when I attempt to @Inject the List<IndexClass> into another class, I get a BeanCreationException saying no matching bean of type IndexClass was found for dependency collection IndexClass.

    Am I just missing something simple?

    Code:
    @Configuration
    public class IndexClassConfiguration {
    	
    	@Value("${configuredIndexClassNames}")
    	private String configuredIndexClassNames;
    	
    	@Inject
    	private IndexClassRepository indexClassRepository;
    	
    	@Bean
    	public List<IndexClass> configuredIndexClasses() throws IndexClassUnknownException {
    		List<IndexClass> configuredIndexClasses = new ArrayList<IndexClass>();
    		
    		for(String name : configuredIndexClassNames.split(",")) {
    			IndexClass indexClass = indexClassRepository.findOne(name);
    			
    			if(indexClass != null)
    				configuredIndexClasses.add(indexClass);
    			else
    				throw new IndexClassUnknownException(name);
    		}
    		
    		return configuredIndexClasses;
    	}
    }

  • #2
    You need to inject by type.

    Comment

    Working...
    X