Announcement Announcement Module
No announcement yet.
Unable to scan for repositories Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unable to scan for repositories

    I am new to spring data and am having some trouble detecting the repositories. I cannot see what's wrong with my setup. Please take a look .. ur help is appreciated.

    HTML Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans:beans xmlns:beans=""
    	<repositories base-package="jpa.examples.repository" />

    The JPA configuration is

    package jpa.examples.config;
    import java.util.HashMap;
    import java.util.Map;
    import javax.sql.DataSource;
    import org.hibernate.dialect.MySQL5Dialect;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
    import org.springframework.jdbc.datasource.DriverManagerDataSource;
    import org.springframework.transaction.PlatformTransactionManager;
    import org.springframework.transaction.annotation.EnableTransactionManagement;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.ComponentScan;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.context.annotation.ImportResource;
    import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
    import org.springframework.jdbc.datasource.DriverManagerDataSource;
    import org.springframework.jdbc.datasource.init.DatabasePopulator;
    import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
    import org.springframework.orm.jpa.JpaTransactionManager;
    import org.springframework.orm.jpa.JpaVendorAdapter;
    import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
    import org.springframework.orm.jpa.vendor.Database;
    import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
    import org.springframework.transaction.annotation.EnableTransactionManagement;
    import jpa.examples.account.JdbcAccountRepository;
    @ImportResource( "classpath*:*springDataConfig.xml" )
    public class PersistenceJPAConfig{
    	public Map<String, Object> jpaProperties() {
    		Map<String, Object> props = new HashMap<String, Object>();
    		props.put("hibernate.dialect", MySQL5Dialect.class.getName());
    		props.put("", "update");
    //		props.put("hibernate.cache.provider_class", HashtableCacheProvider.class.getName());
    		return props;
       public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean(){
          LocalContainerEntityManagerFactoryBean factoryBean 
           = new LocalContainerEntityManagerFactoryBean();
          factoryBean.setDataSource( dataSource() );
          factoryBean.setPackagesToScan( new String[ ] { "jpa.examples" } ); //scan for repositories
          JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(){
          factoryBean.setJpaVendorAdapter( vendorAdapter );
          return factoryBean;
       public DataSource dataSource(){
          DriverManagerDataSource dataSource = new DriverManagerDataSource();
          dataSource.setDriverClassName( "com.mysql.jdbc.Driver" );
          dataSource.setUrl( "jdbc:mysql://localhost:3306/jpaexamples" );
          dataSource.setUsername( "root" );
          dataSource.setPassword( "" );
          return dataSource;
       public PlatformTransactionManager transactionManager(){
          JpaTransactionManager transactionManager = new JpaTransactionManager();
           entityManagerFactoryBean().getObject() );
          return transactionManager;
       public PersistenceExceptionTranslationPostProcessor exceptionTranslation(){
          return new PersistenceExceptionTranslationPostProcessor();

    The repository is

    public interface AccountRepository extends JpaRepository<Account, Long> {
    	public List<Account> findByUsername(String userEmail);

    The service impl class is shown below. The interface is not shown.

    public class AccountServiceImpl implements AccountService {
    	private AccountDao accountDao;
    	private AccountRepository repo;
    	public Account getAccountById(long accountId) {
    		Account account = repo.findOne(accountId);
    		return account;
    	public List<Account> getAccounts() {
    		return repo.findAll();

    When I try to start up the server I get the following error.

    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'AccountServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [jpa.examples.repository.AccountRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency.
    Last edited by lilolme; Feb 24th, 2012, 10:32 PM. Reason: typo

  • #2
    Found the problem

    Just in case it might help someone..
    It was of course a class path issue but it took me a while to solve it. I changed the class path to this and it worked.

    @ImportResource( "classpath:jpa/examples/config/springDataConfig.xml" )


    • #3
      If the output runs through a few repositorys but ends with something similar to the below (most probably with different repositorys failing) and ultimately stopping your updating process then there is a good chance you can fix it by just removing those failing sources from the software sources.

      Err W: Failed to fetch[/url] 404 Not Found
      W: Failed to fetch
      E: Some index files failed to download, they have been ignored, or old ones used instead.


      • #4

        you can go through this site to solve your issue.....
        Last edited by hasselcloud; Mar 5th, 2012, 01:53 PM.