Announcement Announcement Module
No announcement yet.
Autodetection fail Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Autodetection fail

    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

    public abstract class LanguageDao extends JpaCrudRepository<Language, Long>
    		implements JpaRepository<Language, Long> {
    The 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) {
    	public String index() {
    		return "test/index";
    And the configuration to enable component scanning

    HTML 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 base-package="test.external"></context:component-scan>
    As result I'm receiving the message
    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)}
    What am I doing wrong?

  • #2
    This is the class that should be autodetected
    No itsn't... It is abstract an abstract class cannot be instantiated so basically your @Component is useless.

    Judging by the classes/interfaces you are using Spring DATA I suggest a read of the reference guide of the Spring Data Jpa project.


    • #3
      Thanks Marten.
      Tha 'abstract' was only here, not in the code... Sorry.
      However, once I renamed the classes according to Spring data conventions it worked.

      Thanks again,