Announcement Announcement Module
Collapse
No announcement yet.
Unable to scan for repositories Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns="http://www.springframework.org/schema/data/jpa"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/data/jpa
        http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
    
    	<repositories base-package="jpa.examples.repository" />
    
    </beans:beans>

    The JPA configuration is


    Code:
    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.social.connect.jdbc.JdbcUsersConnectionRepository;
    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.core.io.ClassPathResource;
    import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
    import org.springframework.data.repository.RepositoryDefinition;
    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;
    
    @Configuration
    @EnableTransactionManagement
    //@ImportResource("classpath:springDataConfig.xml")
    @ImportResource( "classpath*:*springDataConfig.xml" )
    public class PersistenceJPAConfig{
       
    	@Bean
    	public Map<String, Object> jpaProperties() {
    		Map<String, Object> props = new HashMap<String, Object>();
    		props.put("hibernate.dialect", MySQL5Dialect.class.getName());
    		props.put("hibernate.hbm2ddl.auto", "update");
    //		props.put("hibernate.cache.provider_class", HashtableCacheProvider.class.getName());
    		return props;
    	}
    	
       @Bean
       public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean(){
          LocalContainerEntityManagerFactoryBean factoryBean 
           = new LocalContainerEntityManagerFactoryBean();
          
          factoryBean.setDataSource( dataSource() );
          factoryBean.setPackagesToScan( new String[ ] { "jpa.examples" } ); //scan for repositories
          
          JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(){
             {
            	 jpaProperties();
             }
          };
          factoryBean.setJpaVendorAdapter( vendorAdapter );
          return factoryBean;
       }
       
       @Bean
       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;
       }
      
       
       @Bean
       public PlatformTransactionManager transactionManager(){
          JpaTransactionManager transactionManager = new JpaTransactionManager();
          transactionManager.setEntityManagerFactory( 
           entityManagerFactoryBean().getObject() );
          
          return transactionManager;
       }
       
       @Bean
       public PersistenceExceptionTranslationPostProcessor exceptionTranslation(){
          return new PersistenceExceptionTranslationPostProcessor();
       }
    }

    The repository is

    Code:
    @Transactional
    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.

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

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

    Code:
    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" )

    Comment


    • #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 ppa.launchpad.net
      Err ppa.launchpad.net W: Failed to fetch ppa.launchpad.net/bugs-sehe/gparted/ubuntu/dists/maverick/main/source/Sources.gz[/url] 404 Not Found
      W: Failed to fetch ppa.launchpad.net/bugs-sehe/gparted/ubuntu/dists/maverick/main/binary-amd64/Packages.gz
      E: Some index files failed to download, they have been ignored, or old ones used instead.

      Comment


      • #4
        svn.apache.org/.../repository/scanner/DefaultRepositoryScanner.java


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

        Comment

        Working...
        X