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

找不到Repository类要求bean entityManagerFactory

越鸿才
2023-03-14
 .   ____          _            __ _ _
/\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.8.RELEASE)

2019-09-24 16:13:29.074  INFO 3136 --- [           main] 
com.accounts.rtgsneft.Application        : Starting Application on HO-W- 
Ankushpc with PID 3136 (D:\Rocky\workspaces\acounts-projects\rtgs-neft- 
v1.0\target\classes started by Rocky in D:\Rocky\workspaces\acounts- 
projects\rtgs-neft-v1.0)
2019-09-24 16:13:29.076  INFO 3136 --- [           main] 
com.accounts.rtgsneft.Application        : No active profile set, falling 
back to default profiles: default
2019-09-24 16:13:29.530  INFO 3136 --- [           main] 
.s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data 
repositories in DEFAULT mode.
2019-09-24 16:13:29.584  INFO 3136 --- [           main] . 
s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository 
scanning in 48ms. Found 4 repository interfaces.
2019-09-24 16:13:29.910  INFO 3136 --- [           main] 
trationDelegate$BeanPostProcessorChecker : Bean 
'org.springframework.hateoas.config.HateoasConfiguration' of type [org.springframework.hateoas.config.HateoasConfiguration$$EnhancerBySpringCGLIB$$3c9c44bd] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-09-24 16:13:30.143  INFO 3136 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8086 (http)
2019-09-24 16:13:30.160  INFO 3136 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-09-24 16:13:30.160  INFO 3136 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.24]
2019-09-24 16:13:30.264  INFO 3136 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-09-24 16:13:30.264  INFO 3136 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1158 ms
2019-09-24 16:13:30.399  WARN 3136 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'beneficiaryController': Unsatisfied dependency expressed through field 'beneficiaryService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'beneficiaryMasterServiceImpl': Unsatisfied dependency expressed through field 'beneficiaryRepo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'beneficiaryMasterRepository': Cannot create inner bean '(inner bean)#3ac04654' 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)#3ac04654': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
2019-09-24 16:13:30.402  INFO 3136 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2019-09-24 16:13:30.416  INFO 3136 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run 
your application with 'debug' enabled.
2019-09-24 16:13:30.465 ERROR 3136 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

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

Description:

Field beneficiaryRepo in 
com.accounts.rtgsneft.service.BeneficiaryMasterServiceImpl required a bean 
named 'entityManagerFactory' that could not be found.

The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean named 'entityManagerFactory' in your configuration.

>

  • 启动ApplicationContext时出错。若要显示自动配置报告,请在启用“debug”的情况下重新运行应用程序

    设置构造函数参数时无法解析对bean“Entity ManagerFactory”的引用

    找不到名为“Entity ManagerFactory”的bean

    Field repository需要一个名为“Entity ManagerFactory”的bean,但找不到该bean

    Spring数据JPA-没有定义名为'Entity ManagerFactory‘的bean;自动连线依赖项注入失败

    这是我在调试时尝试的解决方案。

      null

    我的pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
    http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.7.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.accounts.rtgsneft</groupId>
    <artifactId>rtgsneft</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>rtgsneft</name>
    <description>Gold's Gym Account department rtgs neft software</description>
    
    <properties>
        <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-data-rest</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
    
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${basedir}/src/main/resources/static/</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${basedir}/src/main/rtgs-neft/dist/rtgs-neft</directory>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    </project>
    

    我的受益人控制器.java

    package com.accounts.rtgsneft.controller;
    
    import java.util.List;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.http.HttpStatus;
    import org.springframework.http.ResponseEntity;
    import org.springframework.web.bind.annotation.CrossOrigin;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.PostMapping;
    import org.springframework.web.bind.annotation.RequestBody;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    import com.accounts.rtgsneft.model.BeneficiaryMaster;
    import com.accounts.rtgsneft.service.BeneficiaryMasterService;
    
    /**
    * @author Rocky
    *
    */
    @CrossOrigin(origins = "*", maxAge = 3600)
    @RestController
    @RequestMapping("beneficiary")
    public class BeneficiaryController {
    
    @Autowired
    BeneficiaryMasterService beneficiaryService;
    
    @GetMapping("all-beneficiary")
    public ResponseEntity<?> getBeneficiaries() {
        List<BeneficiaryMaster> beneficiaries = beneficiaryService.gettingBeneficiaries();
        return new ResponseEntity<>(beneficiaries, HttpStatus.OK);
    }
    
    @PostMapping("new-beneficiary")
    public ResponseEntity<?> postBeneficiary(@RequestBody BeneficiaryMaster beneficiary) {
        boolean beneficiaryRegistered = beneficiaryService.registerBeneficiary(beneficiary);
        return new ResponseEntity<>(beneficiaryRegistered, HttpStatus.OK);
    }
    
    @PostMapping("single-beneficiary")
    public ResponseEntity<?> selectedBeneficiary(@RequestBody BeneficiaryMaster beneficiaryOBJ) {
        BeneficiaryMaster beneficiary = beneficiaryService.getBeneficiary(beneficiaryOBJ.getAccountNumber());
        return new ResponseEntity<>(beneficiary, HttpStatus.OK);
    }
    }
    

    我的受益人MasterService.java

    package com.accounts.rtgsneft.service;
    
    import java.util.List;
    
    import com.accounts.rtgsneft.model.BeneficiaryMaster;
    public interface BeneficiaryMasterService {
    List<BeneficiaryMaster> gettingBeneficiaries();
    boolean registerBeneficiary(BeneficiaryMaster beneficiary);
    BeneficiaryMaster getBeneficiary(Long accountNumber);
    }
    
    package com.accounts.rtgsneft.service;
    import java.util.List;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import com.accounts.rtgsneft.model.BeneficiaryMaster;
    import com.accounts.rtgsneft.repos.BeneficiaryMasterRepository;
    @Service
    public class BeneficiaryMasterServiceImpl implements BeneficiaryMasterService {
    
    @Autowired
    BeneficiaryMasterRepository beneficiaryRepo;
    
    @Override
    public List<BeneficiaryMaster> gettingBeneficiaries() {     
        return beneficiaryRepo.findAll();
    }
    
    @Override
    public boolean registerBeneficiary(BeneficiaryMaster beneficiary) {
    
        boolean benficiaryStatusFlag = false;
        BeneficiaryMaster benficiaryStatus= beneficiaryRepo.save(beneficiary);
        if(benficiaryStatus != null ) {
            benficiaryStatusFlag = true;
        }
        return benficiaryStatusFlag;
    }
    
    @Override
    public BeneficiaryMaster getBeneficiary(Long accountNumber) {
        return beneficiaryRepo.getOne(accountNumber);
    }
    }
    
    package com.accounts.rtgsneft.repos;
    
    import org.springframework.data.jpa.repository.JpaRepository;
    import org.springframework.stereotype.Repository;
    import com.accounts.rtgsneft.model.BeneficiaryMaster;
    @Repository
    public interface BeneficiaryMasterRepository extends 
    JpaRepository<BeneficiaryMaster, Long> {}
    

    如果有其他的解决方案,请推荐给我。我使用的是Spring2.17,我想在tomcat中部署应用程序war文件,在这样做之前,我必须对它进行测试,以检查它是否还在工作。

  • 共有1个答案

    太叔京
    2023-03-14

    Spring Data JPA默认情况下会查找名为EntityManagerFactory的EntityManagerFactory。请查看EnableJpaRepositories的Javadoc的这一部分或Spring Data JPA文档的表2.1。

    这意味着您要么必须将emf bean重命名为entityManagerFactory,要么将Spring配置更改为:

    (如果您使用的是XML)

    @EnableJParepositories(BasePackages=“Your.Package”,EntityManagerFactoryRef=“EMF”)

    (如果您使用的是Java配置)

     类似资料:
    • 问题内容: 我有一个定义如下的类: 为什么我在声明之前出现错误 我只是在这里将整数变量的值与0进行比较。根据错误,我需要创建一个类。请让我知道这里出了什么问题。 问题答案: 您需要在可执行块(方法,静态初始化程序,构造函数等)中编写语句

    • 问题内容: 我正在使用以下文件在Ubuntu 12.04中安装几个Python软件包: 和这两个命令: (第一个下载软件包,第二个安装软件包)。 该过程经常因错误而停止: 我用以下方法手动修复: 然后再次运行第二个命令。 但这仅适用于 该 特定程序包。当我再次运行第二个命令时,该过程现在停止,并抱怨 另一个 必需的程序包,我需要再次重复该过程,即:手动安装新的必需的程序包(使用上面的命令),然后运

    • 找不到满足Flask pip安装-U Flask要求的版本 收集烧瓶无法获取URLhttps://pypi.python.org/simple/flask/:确认ssl证书时出现问题:[ssl:TLSV1\u警报\u协议\u版本]TLSV1警报协议版本(\u ssl.c:590)-正在跳过 找不到满足要求的版本(来自版本:) 未找到烧瓶的匹配分布

    • 问题内容: 我在virtualenv中安装pytz时遇到问题。 下载/解压pytz 找不到满足pytz要求的版本(来自以下版本:2009r,2008b,2009f,2008c,2007g,2011g,2005m,2011e,2007f,2011k,2007k,2006j,2008h,2008i,2011e,2008a,2009e,2006g, 2011j,2010l,2005m,2008i,200

    • 我安装了最新版本的Python和最新版本的。然后我在PyCharm中安装了一些模块(Numpy、Pandas等),但当我尝试安装Tensorflow时,它没有安装,并且我得到了错误消息: 找不到满足TensorFlow要求的版本(来自Versions:)找不到TensorFlow的匹配发行版。 然后我尝试从命令提示符安装TensorFlow,得到了相同的错误消息。不过,我确实成功地安装了TFLea