Results 1 to 5 of 5

Thread: Getting " No matching bean of type [..] found for dependency" using spring-data-jpa

  1. #1
    Join Date
    Jul 2010
    Posts
    8

    Unhappy Getting " No matching bean of type [..] found for dependency" using spring-data-jpa

    I am using spring-mvc 3.1.0.RELEASE,recently I want to add spring-data-jpa 1.0.3.RELEASE in my web project, but failed. I got error:
    No matching bean of type [..] found for dependency, expected at least 1 bean which qualifies as autowire candidate for this dependency

    I have a post in stackoverflow.

    I am wondering how to get rid of this error. I am also curious about how spring creating a instance of my repository interface. And is there any special configuration?

  2. #2
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,806

    Default

    Hello

    Next time use code tags, and post here the complete error stack trace. The error is obvious, a missing bean dependency, I hope you have a correct configuration to scan the packages and get the annotated beans

    I am also curious about how spring creating a instance of my repository interface. And is there any special configuration?
    Read the Spring Reference documentation for more details, there are many examples too
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  3. #3
    Join Date
    Jul 2010
    Posts
    8

    Default

    Thanks for the reply. I put my code here:

    My configuration:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans" 
           	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           	xmlns:p="http://www.springframework.org/schema/p" 
           	xmlns:tx="http://www.springframework.org/schema/tx"
           	xmlns:context="http://www.springframework.org/schema/context"
           	xmlns:jdbc="http://www.springframework.org/schema/jdbc"
           	xmlns:jpa="http://www.springframework.org/schema/data/jpa"
           	xmlns:util="http://www.springframework.org/schema/util"
           	xsi:schemaLocation="
    			http://www.springframework.org/schema/beans 
    			http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
    			http://www.springframework.org/schema/tx 
    			http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
    			http://www.springframework.org/schema/context
    			http://www.springframework.org/schema/context/spring-context-3.1.xsd
    			http://www.springframework.org/schema/jdbc 
    			http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
    			http://www.springframework.org/schema/data/jpa
       			http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
    			http://www.springframework.org/schema/util 
    			http://www.springframework.org/schema/util/spring-util-3.1.xsd">
    	<!-- Activate Spring Data JPA repository support -->
      	<jpa:repositories base-package="com.mypackage.repository" />
    </beans>
    My repository:
    Code:
    package com.mypackage.repository;
    import org.springframework.data.domain.Page;
    import org.springframework.data.domain.Pageable;
    import org.springframework.data.jpa.repository.JpaRepository;
    import com.mypackage.pbo.PSubject;
    public interface SubjectRepository extends JpaRepository<PSubject, String>{
    	public Page<PSubject> findByType(String title, Pageable pageable);
    	public Page<PSubject> findByType(String title);
    	public Page<PSubject> findByMacaddress(String macaddress, Pageable pageable);
    	public Page<PSubject> findByMacaddress(String macaddress);
    	public Page<PSubject> findByUri(String uri);
    }
    My service:
    Code:
    ....
    @Transactional
    @Service("subjectService")
    public class SubjectServiceImpl implements SubjectService
    {
    	private final SubjectRepository subjectRepository;
    	@Autowired
    	public SubjectServiceImpl(SubjectRepository subjectRepository){
    		this.subjectRepository = subjectRepository;
    	}
    It seems everything just like the example of spring site except I integrate it into my spring mvc project. But when starting my project, I got error:

    org.springframework.beans.factory.NoSuchBeanDefini tionException: No matching bean of type [com.mypa.repository.SubjectRepository] found for dependency


    Quote Originally Posted by dr_pompeii View Post
    Hello

    Next time use code tags, and post here the complete error stack trace. The error is obvious, a missing bean dependency, I hope you have a correct configuration to scan the packages and get the annotated beans


    Read the Spring Reference documentation for more details, there are many examples too

  4. #4
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,806

    Default

    Hello

    Code:
    org.springframework.beans.factory.NoSuchBeanDefini tionException: 
    No matching bean of type [com.mypa.repository.SubjectRepository] found for dependency
    OK

    I am not an expert with Spring Data but according with

    Code:
            private final SubjectRepository subjectRepository;
    
    	@Autowired
    	public SubjectServiceImpl(SubjectRepository subjectRepository){
    		this.subjectRepository = subjectRepository;
    	}
    1) why you are using final?
    2) Where you have defined a class annotated with @Repository to be scanned and be used within the application context and It class implements the interface SubjectRepository?
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  5. #5
    Join Date
    Jul 2010
    Posts
    8

    Default

    Hi, I removed "final",nothing changed. For your doubt 2: Where you have defined a class annotated with @Repository to be scanned and be used within the application context

    There are two kinds of repositories in Spring data jpa, what you said is a classic one. And in the tutorial of spring data jpa, it said you can just extends a interface of spring data jpa, no need to implement this interface, and no annotation needed.



    Quote Originally Posted by dr_pompeii View Post
    Hello

    Code:
    org.springframework.beans.factory.NoSuchBeanDefini tionException: 
    No matching bean of type [com.mypa.repository.SubjectRepository] found for dependency
    OK

    I am not an expert with Spring Data but according with

    Code:
            private final SubjectRepository subjectRepository;
    
    	@Autowired
    	public SubjectServiceImpl(SubjectRepository subjectRepository){
    		this.subjectRepository = subjectRepository;
    	}
    1) why you are using final?
    2) Where you have defined a class annotated with @Repository to be scanned and be used within the application context and It class implements the interface SubjectRepository?

Tags for this Thread

Posting Permissions

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