Announcement Announcement Module
Collapse
No announcement yet.
Getting " No matching bean of type [..] found for dependency" using spring-data-jpa Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment


    • #3
      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


      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

      Comment


      • #4
        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?

        Comment


        • #5
          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.



          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?

          Comment

          Working...
          X