Spring-boot错误:考虑在配置中定义名为“entityManagerFactory”的bean

问题描述 投票:1回答:1

我正在运行我的Spring Boot应用程序,但它给了我与EntityManagerFactory相关的错误。我应该创建自己的EntityManager吗?它不包含在spring-boot-starter-data-jpa

2018-08-21 12:27:18.993  WARN 2728 --- [           main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'office365InstanceServiceImpl': Unsatisfied dependency expressed through field 'instanceRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'office365InstanceRepository': Cannot create inner bean '(inner bean)#252a8aae' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#252a8aae': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
2018-08-21 12:27:19.018  INFO 2728 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-08-21 12:27:19.071 ERROR 2728 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

描述:

Field instanceRepository in com.qualityclouds.qcforoffice365.service.Office365InstanceServiceImpl required a bean named 'entityManagerFactory' that could not be found.

行动:

考虑在配置中定义名为“entityManagerFactory”的bean。

   <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
      </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>transport</artifactId>
        <version>6.3.2</version>
    </dependency>



@SpringBootApplication
@EnableJpaRepositories
public class Qcforoffice365Application {

    public static void main(String[] args) {

        ApplicationContext ctx = SpringApplication.run(Qcforoffice365Application.class, args);

        Driver driver = (Driver) ctx.getBean("QCDriver");

        driver.run();

    }
}


@Repository
public interface Office365InstanceRepository extends CrudRepository<Office365InstanceConfiguration, String> {

}

@Service
public class Office365InstanceServiceImpl implements Office365InstanceService {

    @Autowired
    private Office365InstanceRepository instanceRepository;

    @Override
    public Office365InstanceConfiguration findById(String id) {
        return instanceRepository.findById(id).orElse(null);
    }

}

这是package structure

spring-boot entitymanager
1个回答
0
投票

最后我找到了解决方案。我只需要删除.m2中的存储库并再次尝试。猜猜这是与其他项目的一些依赖相关的东西。

© www.soinside.com 2019 - 2024. All rights reserved.