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.


Reply With Quote
