当前位置: 首页 > 知识库问答 >
问题:

未找到EntityManger bean?

蓝恩
2023-03-14

启动ApplicationContext时出错。若要显示条件报告,请在启用“调试”的情况下重新运行应用程序。2017-11-21 15:46:26.983错误6272---[main]O.S.B.D.LoggingFailureAnalysisReporter
应用程序无法启动****************************************************************

描述:com.learing.demo.StatusService中的字段存储库需要一个名为“Entity ManagerFactory”的bean,但找不到该bean。行动:

考虑在配置中定义一个名为'Entity ManagerFactory‘的bean。

进程已完成,退出代码为%1

package com.learing.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.transaction.annotation.EnableTransactionManagement;

    @SpringBootApplication
    public class DemoApplication {
        public static void main(String[] args) {
            SpringApplication.run(DemoApplication.class, args);
        }
    }
package com.learing.demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class StatusController {

@Autowired
private StatusService statusService;

@RequestMapping("/getEmpStatus")
public List<Employee> GetAllEmployeeStatus(){
    return statusService.GetAllEmpStatus();
}

@RequestMapping("/getEmpStatus/{id}")
public Employee GetAllEmployeeStatus(@PathVariable int id){
    return statusService.GetEmpStatus(id);
}

@RequestMapping(method= RequestMethod.POST, value="/getEmpStatus")
 public void  AddEmployeeStatus(@RequestBody Employee employee){
    statusService.AddEmployeeStatus(employee);

}
@RequestMapping(method = RequestMethod.PUT, value="/getEmpStatus/{id}")
public void  UpdateStatus(@RequestBody Employee employee, @PathVariable int id){
     statusService.UpdateStatus(employee,id);
}
@RequestMapping(method= RequestMethod.DELETE, value="/getEmpStatus/{id}")
public void  UpdateStatus(@PathVariable int id){
    statusService.DeleteStatus(id);
}

}

StatusService类

    package com.learing.demo;

    import org.springframework.beans.factory.annotation.Autowired;

    import org.springframework.context.annotation.Bean;
    import org.springframework.stereotype.Service;

    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;

    @Service
    public class StatusService {

        @Autowired
        public RepositoryImpl repository;

        private List<Employee> employees = new ArrayList<>(Arrays.asList(new Employee(1, "NSIN253", "Kalpa", "BHS-Mapping", "Mapping doc Completed"), new Employee(2, "NSIN254", "Fareeda", "BHS-Mapping", "Mapping doc Completed"), new Employee(3, "NSIN252", "KrishnaVeni", "BHS-Mapping", "Mapping doc Completed")));


        public List<Employee> GetAllEmpStatus() {
            return employees;
        }

        public Employee GetEmpStatus(int id) {
            return employees.stream().filter(employee -> employee.getiD() == id).findFirst().get();
        }

        public void AddEmployeeStatus(Employee employee) {
            repository.save(employee);
        }

        public void UpdateStatus(Employee employee, int id) {
            for (int i = 0; i < employees.size(); i++) {
                Employee emp = employees.get(i);
                if (emp.getiD() == id) {
                    employees.set(i, employee);
                }
            }
        }

        public void DeleteStatus(int id) {
            employees.removeIf(emp -> emp.getiD() == id);
        }
    }

RepositoryImpl类

    package com.learing.demo;

    import org.springframework.data.repository.CrudRepository;
    import org.springframework.stereotype.Repository;

    @Repository
    public interface RepositoryImpl extends CrudRepository<Employee,Integer> {

    }
spring.datasource.url=jdbc:sqlserver://localhost:1433;databaseName=EmployeeDb
    spring.datasource.username=xxxx
    spring.datasource.password=xxxxx
    spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
    spring.jpa.show-sql=true
    spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
    spring.jpa.hibernate.ddl-auto =update
<?xml version="1.0" encoding="UTF-8"?>
<groupId>com.learing</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>demo</name>
<description>Demo project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.0.BUILD-SNAPSHOT</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>com.microsoft.sqlserver</groupId>
        <artifactId>mssql-jdbc</artifactId>
        <scope>runtime</scope>

    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.1.4.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>5.2.3.Final</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>spring-snapshots</id>
        <name>Spring Snapshots</name>
        <url>https://repo.spring.io/snapshot</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

<pluginRepositories>
    <pluginRepository>
        <id>spring-snapshots</id>
        <name>Spring Snapshots</name>
        <url>https://repo.spring.io/snapshot</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </pluginRepository>
    <pluginRepository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>

共有1个答案

戈华茂
2023-03-14

您需要从POM中删除以下内容:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>4.1.4.Final</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>5.2.3.Final</version>
</dependency>
 类似资料:
  • 当我运行我的Android应用程序从eclipse,我得到这个错误。 从日蚀错误复制粘贴 然而,我的亚洲开发银行就在它说的不在的地方。 出了什么问题,如何解决? 我将cd放入adb所在的目录()中,输入adb并显示 adb是绿色的,这意味着它是可执行的,对吗? 例如,dx也是绿色的,当我在命令提示符中输入dx时,它工作了... adb怎么了?

  • 块引号 J拥有一个包含maven父项目(parent)和子项目(Domain,Web,Win)的Eclipse工作区。父pom包含wicket-spring-boot-starter-parent

  • 当我尝试使用或出现以下错误 JAVA错误:sun。安全ssl。SSLSessionImpl。(Lsun/security/ssl/ProtocolVersion;Lsun/security/ssl/CipherSuite;Ljava/util/Collection;Lsun/security/ssl/SessionId;Ljava/lang/String;I)V 在sun.security.ssl

  • 问题内容: 通过扫描程序读取文件时,程序中出现运行时异常。 我的代码是: 问题答案: 与你需要检查,如果存在与下一行 所以循环变成 是读者返回null 当然在这段代码中,这取决于输入的格式是否正确

  • 我是新的Python开发和尝试使用pipenv。我运行命令,它成功运行: 然而,当我在一个新的根项目目录中运行命令时,我收到以下消息:。我怀疑我可能需要修改我的. bashrc,但是我不清楚要向文件中添加什么,或者是否需要修改。

  • 我用Android Studio为Unity做了一个jar插件。我的插件使用。但找不到该类。Unity的控制台向我显示了以下错误:

  • 我不知道如何处理以下错误,我已经搜索了网络,但没有找到任何东西: 以及: 我在gradle应用程序中的依赖项:

  • 我试图从netbeans连接到sqlite,但它没有得到我的conexion类 这是我的代码: 这是我的错误: Java语言lang.NoClassDefFoundError:Petrocabimas\u app/Conexion(错误名称:Petrocabimas\u app/Conexion)。lang.ClassLoader。在java中定义Class1(本机方法)。lang.ClassLo