【问题标题】:I am trying to learn spring boot. i am facing error while connecting spring boot project with remote oracle DB我正在尝试学习弹簧靴。将 Spring Boot 项目与远程 Oracle DB 连接时遇到错误
【发布时间】:2020-07-17 06:04:28
【问题描述】:

o.h.engine.jdbc.spi.SqlExceptionHelper:SQL 错误:1427,SQLState:21000 2020-04-05 13:08:39.334 错误 25252 --- [main] o.h.engine.jdbc.spi.SqlExceptionHelper:ORA-01427:单行子查询返回多于一行

2020-04-05 13:08:39.377 WARN 25252 --- [main] ConfigServletWebServerApplicationContext:上下文初始化期间遇到异常-取消刷新尝试:org.springframework.beans.factory.BeanCreationException:创建名为“entityManagerFactory”的bean时出错' 在类路径资源 [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class] 中定义:调用 init 方法失败;嵌套异常是 javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory;嵌套异常是 org.hibernate.exception.DataException:访问表元数据时出错 2020-04-05 13:08:39.377 INFO 25252 --- [main] com.zaxxer.hikari.HikariDataSource:HikariPool-1 - 已启动关闭... 2020-04-05 13:08:39.608 INFO 25252 --- [main] com.zaxxer.hikari.HikariDataSource:HikariPool-1 - 关闭完成。 2020-04-05 13:08:39.610 INFO 25252 --- [main] o.apache.catalina.core.StandardService:停止服务 [Tomcat] 2020-04-05 13:08:39.651 INFO 25252 --- [主] ConditionEvaluationReportLoggingListener:

启动 ApplicationContext 时出错。要显示条件报告,请在启用“调试”的情况下重新运行您的应用程序。 2020-04-05 13:08:39.664 错误 25252 --- [main] os.boot.SpringApplication:应用程序运行失败

org.springframework.beans.factory.BeanCreationException:在类路径资源 [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class] 中定义名称为“entityManagerFactory”的 bean 创建错误:调用 init 方法失败;嵌套异常是 javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory;嵌套异常是 org.hibernate.exception.DataException:访问表元数据时出错 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE] 在 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE] 在 org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1108) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE] 在 org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE] 在 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE] 在 org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE] 在 org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE] 在 org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE] 在 com.tcs.SpringBootMvcDemoApplica 进入图像描述 heretion.main(SpringBootMvcDemoApplication.java:27) [classes/:na] 引起:javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory;嵌套异常是 org.hibernate.exception.DataException: Error access tables metadata

2:https://i.stack.imgur.com/65p6M.png

【问题讨论】:

  • 请勿发布代码、数据、错误消息等的图片 - 将文本复制或输入到问题中。 How to Ask

标签: spring-boot oracle11g


【解决方案1】:

我最近遇到了同样的问题。而且我重叠了一些依赖项,导致“在类路径资源中定义名称为 'entityManagerFactory' 的 bean 创建错误”

添加以下依赖并检查是否有效。

<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>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

【讨论】:

    【解决方案2】:

    从您的例外情况中我可以看出: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource

    通过查看您的代码:
    您的 custRepo 需要用 @Repository 注释

    最好也添加这些依赖项

    <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    

    【讨论】:

    • 但是在spring starter jpa项目中不是预先定义了hibernate依赖吗?
    • 糟糕,我忘记看你的截图了。
    • 我想我还缺少其他一些东西并且无法弄清楚。这两天卡住了
    • 因为需要你的代码,我不能只看你的日志和 pom 来告诉你
    • 我正在尝试使用oracle db,所以我还需要mysql依赖吗?
    猜你喜欢
    • 1970-01-01
    • 2018-03-13
    • 2021-10-27
    • 1970-01-01
    • 2017-09-25
    • 2020-10-14
    • 2023-03-25
    • 2020-03-16
    • 2021-01-03
    相关资源
    最近更新 更多