Results 1 to 3 of 3

Thread: Autodetection fail

  1. #1
    Join Date
    Jun 2009
    Location
    Vicenza, Italy
    Posts
    84

    Question 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

    Code:
    @Component
    public abstract class LanguageDao extends JpaCrudRepository<Language, Long>
    		implements JpaRepository<Language, Long> {
    
    }
    The controller

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

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Jun 2009
    Location
    Vicenza, Italy
    Posts
    84

    Default

    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,
    Stefano

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •