Teamscontroller
@RestController public class TeamsController { @Autowired private TeamsService teamsService; ... } Application
@SpringBootApplication @ComponentScan(basePackages = {"com.test.api","com.test.service"}) public class Application { public static void main(String[] args) throws Exception{ SpringApplication.run(new Class<?>[] {Application.class, JpaConfig.class}, args); } } Jpaconfig
@Configuration @EnableTransactionManagement @EnableJpaRepositories(basePackages = "com.test.service.repository") public class JpaConfig implements TransactionManagementConfigurer { ... @Bean public LocalContainerEntityManagerFactoryBean configureEntityManagerFactory() { LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean(); entityManagerFactoryBean.setDataSource(configureDataSource()); entityManagerFactoryBean.setPackagesToScan("com.test.model"); ...} ... } Teamsrepository
@Repository public interface TeamsRepository extends JpaRepository<TeamsEntity, Long> { } Teamsservice
public interface TeamsService { Collection<TeamsEntity> findAll(); TeamsEntity findOne(Long id); TeamsEntity create(TeamsEntity teamsEntity); TeamsEntity update(TeamsEntity teamsEntity); void delete(Long id); } TeamsServiceImpl
@Service @Transactional( propagation = Propagation.SUPPORTS, readOnly = true) public class TeamsServiceImpl implements TeamsService { TeamsServiceImpl(){ } @Autowired private TeamsRepository teamsRepository; ... It produces the following error:
org.springframework.beans.factory.BeanCreationException: Error create bean with name 'teamsController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.test.service.TeamsService com.test.api.TeamsController.teamsService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'teamsServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.test.service.repository.TeamsRepository com.test.service.TeamsServiceImpl.teamsRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'teamsRepository': Cannot create inner bean (inner bean) # 1b7a52dd 'of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while using bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: # 1b7a52dd 'Error creating bean with name' (inner bean): 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' is defined
