我正在运行我的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);
}
}
答案 0 :(得分:0)
最后,我找到了解决方案。我只需要删除.m2中的存储库,然后再试一次即可。猜猜这与其他项目的依赖性有关。