I have a Spring application and in it I do not use xml configuration, only Java Config. Everything is OK, but when I try to test it I faced problems wi
You cant use repositories in your configuration class because from configuration classes it finds all its repositories using @EnableJpaRepositories.
@Configuration @EnableWebMvc @EnableTransactionManagement @ComponentScan("com.example") @EnableJpaRepositories(basePackages={"com.example.jpa.repositories"})//Path of your CRUD repositories package @PropertySource("classpath:application.properties") public class JPAConfiguration { //Includes jpaProperties(), jpaVendorAdapter(), transactionManager(), entityManagerFactory(), localContainerEntityManagerFactoryBean() //and dataSource() }
@Service public class RepositoryImpl { @Autowired private UserRepositoryImpl userService; }
@Autowired RepositoryImpl repository;
Usage:
repository.getUserService().findUserByUserName(userName);
Remove @Repository Annotation in ArticleRepository and ArticleServiceImpl should implement ArticleRepository not ArticleService.