Hi everybody,
it's the first I'm trying to use bean autodetection and I'm having some problem.
I'm trying to autodetect a class from an external JAR and then inject it into a controller with the @Autowired annotation.
Here is some code.
This is the class that should be autodetected
The controllerCode:@Component public abstract class LanguageDao extends JpaCrudRepository<Language, Long> implements JpaRepository<Language, Long> { }
And the configuration to enable component scanningCode:@RequestMapping("/test/**") @Controller public class TestController { @Autowired(required = true) private LanguageDao languageDao; public LanguageDao getLanguageDao() { return languageDao; } public void setLanguageDao(LanguageDao languageDao) { this.languageDao = languageDao; } @RequestMapping(method = RequestMethod.POST, value = "{id}") public void post(@PathVariable Long id, ModelMap modelMap, HttpServletRequest request, HttpServletResponse response) { } @RequestMapping public String index() { return "test/index"; } }
As result I'm receiving the messageHTML Code:<context:component-scan base-package="test.project"> <context:exclude-filter expression=".*_Roo_.*" type="regex"/> <context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/> </context:component-scan> <context:component-scan base-package="test.external"></context:component-scan>
What am I doing wrong?Code:GRAVE: Servlet /cmcloud threw load() exception org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [test.external.LanguageDao] 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)}
Thanks,
Stefano


Reply With Quote