In a project with a structure
The structure of the project.

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

    1 answer 1

    As it turned out, the problem was neither in the methods of injecting the Repository into the user DAO and not in the configuration of this kind the wrong packages were specified, but in the name of the factory itself - because Spring Data JPA is looking for an EntityManagerFactory with the instance name entityManagerFactory ; this is evident in the documentation .

    org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' is defined

    Accordingly, it is necessary either to replace the name of the method or indicate to the spring your name, as suggested here .
    PS: Next time I will read the log from the end ¯\_(ツ)_/¯

    • Or you can search the network. This link - the first in the issuance of Google. - Maksim
    • well when you know what to look for. - Krychun Ivan