相关疑难解决方法(0)

在 SpringBoot 中找不到 EntityManagerFactory

我正在尝试使用 MySQL 和 SpringBoot 为员工创建登录名。我使用内存数据库使我的代码工作,但是一旦我将代码切换到 MySQL,它就停止工作。这个项目是一个科学怪人,所以我不确定我的一些组件是否可以一起工作。我不确定是否需要我的 App 类中的所有注释...错误如下:

描述:

Field employeeRepository in io.msela.springbootstarter.employee.EmployeeService 
required a bean named 'entityManagerFactory' that could not be found.
Run Code Online (Sandbox Code Playgroud)

行动:

考虑定义一个'entityManagerFactory'在您的配置中命名的 bean 。

这是我的App课程,它运行整个过程:

package io.msela;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

import io.msela.springbootstarter.employee.EmployeeRepository;

@SpringBootApplication
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class}) //added for MySQL
@ComponentScan({"io.msela"})
@EntityScan("io.msela.springbootstarter")
@EnableJpaRepositories(basePackageClasses = EmployeeRepository.class)
public class EmployeeApiDataApplication {

    public static void main(String[] args) {
        SpringApplication.run(EmployeeApiDataApplication.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

这是 …

java mysql spring-boot

0
推荐指数
1
解决办法
2万
查看次数

标签 统计

java ×1

mysql ×1

spring-boot ×1