创建名称为' entityManagerFactory'的bean时出错在类路径资源中定义:init方法的调用失败

时间:2016-10-15 10:40:05

标签: java spring hibernate spring-mvc jpa

当我编译我的spring项目时,我收到以下错误。

  

使用名称' entityManagerFactory'创建bean时出错。在课堂上定义   路径资源   [组织/ springframework的/引导/自动配置/ ORM / JPA / HibernateJpaAutoConfiguration.class]:   调用init方法失败

我正在使用STS Eclipse和MySql数据库

spring.datasource.url=jdbc:mysql://localhost:3306/stgdb spring.datasource.username=root spring.datasource.password=root spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.jpa.hibernate.ddl-auto=update 中的我的连接字符串是

=================================================

2016-10-15 15:34:38.875[0;39m [31mERROR[0;39m [35m3700[0;39m [2m---[0;39m [2m[           main][0;39m [36mo.s.boot.SpringApplication              [0;39m [2m:[0;39m Application startup failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1076) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:851) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
    at com.s2g.testrestapplication.TestRestApplication.main(TestRestApplication.java:10) [classes/:na]
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:954) ~[hibernate-entitymanager-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:882) ~[hibernate-entitymanager-5.0.11.Final.jar:5.0.11.Final]
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) ~[spring-orm-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353) ~[spring-orm-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:373) ~[spring-orm-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:362) ~[spring-orm-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1642) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    ... 16 common frames omitted
Caused by: org.hibernate.exception.GenericJDBCException: Unable to obtain JDBC Connection
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:95) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.tool.schema.extract.internal.ExtractionContextImpl.getJdbcConnection(ExtractionContextImpl.java:65) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.tool.schema.extract.internal.ExtractionContextImpl.getJdbcDatabaseMetaData(ExtractionContextImpl.java:75) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl.locateTableInNamespace(InformationExtractorJdbcDatabaseMetaDataImpl.java:339) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl.getTable(InformationExtractorJdbcDatabaseMetaDataImpl.java:241) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.tool.schema.extract.internal.DatabaseInformationImpl.getTableInformation(DatabaseInformationImpl.java:105) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigrationToTargets(SchemaMigratorImpl.java:162) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigration(SchemaMigratorImpl.java:60) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:134) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:101) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:472) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879) ~[hibernate-entitymanager-5.0.11.Final.jar:5.0.11.Final]
    ... 22 common frames omitted
Caused by: com.atomikos.jdbc.AtomikosSQLException: Connection pool exhausted - try increasing 'maxPoolSize' and/or 'borrowConnectionTimeout' on the DataSourceBean.
    at com.atomikos.jdbc.AtomikosSQLException.throwAtomikosSQLException(AtomikosSQLException.java:46) ~[transactions-jdbc-3.9.3.jar:na]
    at com.atomikos.jdbc.AbstractDataSourceBean.throwAtomikosSQLException(AbstractDataSourceBean.java:90) ~[transactions-jdbc-3.9.3.jar:na]
    at com.atomikos.jdbc.AbstractDataSourceBean.throwAtomikosSQLException(AbstractDataSourceBean.java:85) ~[transactions-jdbc-3.9.3.jar:na]
    at com.atomikos.jdbc.AbstractDataSourceBean.getConnection(AbstractDataSourceBean.java:347) ~[transactions-jdbc-3.9.3.jar:na]
    at com.atomikos.jdbc.AbstractDataSourceBean.getConnection(AbstractDataSourceBean.java:394) ~[transactions-jdbc-3.9.3.jar:na]
    at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:180) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.tool.schema.extract.internal.ExtractionContextImpl.getJdbcConnection(ExtractionContextImpl.java:62) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    ... 33 common frames omitted
==============================
Pom.xml file

详细错误如下:

<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>

    <groupId>com.s2g.testrestapplication</groupId>
    <artifactId>testrestapplication</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

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

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.1.RELEASE</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>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.2.2</version>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.2.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</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>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.opensaml</groupId>
            <artifactId>opensaml-saml-api</artifactId>
            <version>3.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jersey</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jta-atomikos</artifactId>
        </dependency>
    </dependencies>

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


</project>
apiVersion: v1
kind: Service
metadata:
 labels:
   name: mongo
 name: mongo
spec:
 ports:
 - port: 27017
   targetPort: 27017
 selector:
   name: mongo

34 个答案:

答案 0 :(得分:66)

使用java 9的人包含这种依赖: -

<dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.0</version>
</dependency>

答案 1 :(得分:57)

我首先要添加以下依赖项:

<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>

更新 或简单地添加以下依赖项。

<dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.0</version>
</dependency>

答案 2 :(得分:8)

添加依赖项并没有解决我的问题。

这个问题发生在我的最后,因为&#34;额外的&#34;作为&#34; @ Entity&#34;的一部分的字段类和不存在于数据库中。

我从@Entity类中删除了其他字段并且它有效。

古德勒克。

答案 3 :(得分:7)

我也面临着同样的问题。我正在使用Java9,并且在pom文件中遵循以下依赖关系:

<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-jdbc</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

在pom中添加以下依赖项后,该问题已解决:

    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.0</version>
    </dependency>

答案 4 :(得分:5)

我怀疑hibernate-corehibernate-entitymanager依赖项的jar文件已损坏或未在您的计算机上正确安装。

我建议您从Maven本地存储库中删除名为hibernate-corehibernate-entitymanager的文件夹,然后Maven将重新安装它们。

Maven本地存储库的默认位置是Windows中的C:\Documents and Settings\[USERNAME]\.m2或Linux / Mac中的~/.m2

答案 5 :(得分:3)

对于那些使用Gradle而不是Maven的用户,请将其添加到构建文件中的依赖项:

compile('javax.xml.bind:jaxb-api:2.3.0')

答案 6 :(得分:1)

尝试使用@EnableTransactionManagement注释该类。我遇到了同样的问题,并通过添加它来解决。

@EnableTransactionManagement
public class ConfigurationBean {
}

答案 7 :(得分:1)

我在Eclipse Luna上遇到了同样的问题。 我发现我正在使用JDK12和Java 1.8。我将JDK更改为JDK8,此问题已解决。 如果要在Eclipse中检查JDK,请转至

Window-> Preferences-> Java- >Installed JREs 

,然后检查它们是否与您的项目兼容。 祝你好运!

答案 8 :(得分:1)

例如,对于我而言,删除以下任何注释都会导致显示错误消息“ entityManagerFactory”。

 @Id
  @GeneratedValue(strategy=GenerationType.AUTO)

@ManyToMany(targetEntity=listOfObject_x.class)

添加缺少的注释后,错误消息消失。

package mypackage_unameit;
import javax.persistence.PrePersist;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import lombok.Data;

@Data
@Entity
public class Someclasss {

  @Id
  @GeneratedValue(strategy=GenerationType.AUTO)
  private Long id;

  @NotNull
  @Size(min=5, message="Name must be at least 5 characters long")
  private String name;

  private Date createdAt;

  @ManyToMany(targetEntity=listOfObject_x.class)
  @Size(min=1, message="You must choose at least 1 ingredient")
  private List<listOfObject_x>   = new ArrayList<>();

  @PrePersist
  void createdAt() {
    this.createdAt = new Date();
  }
}

答案 9 :(得分:1)

该错误也可能与以下事实有关:例如,当您输入错误的数据库名称时,您的“ spring.datasource.url”中就有错误

答案 10 :(得分:0)

尝试更改春季版本。我遇到了同样的问题,对我有用

答案 11 :(得分:0)

对我来说,这是另一个错误的结果

  

org.postgresql.util.PSQLException:致命:用户的密码身份验证失败

这意味着您只需要查看身份验证凭据

答案 12 :(得分:0)

对于那些不使用JPA而是更喜欢排除entityManagerFactory并使用Spring Data JDBC或Spring JDBC的用户可以排除Bean以避免异常

@SpringBootApplication(exclude = {HibernateJpaAutoConfiguration.class})

答案 13 :(得分:0)

对我来说,它是application.properties上数据库的名称。当我提供正确的名称后,它可以正常工作。

答案 14 :(得分:0)

我通过为其他字段定义反向关系注释来解决我的问题

答案 15 :(得分:0)

仍然存在相同问题的人。请在application.properties中添加以下行

# The SQL dialect makes Hibernate generate better SQL for the chosen database
## I am using Mysql8 so I have declared MySQL8Dialect if you have other versions just add ## that version number
spring.jpa.properties.hibernate.dialect =  org.hibernate.dialect.MySQL8Dialect

答案 16 :(得分:0)

就我而言,尝试使Proguard + Spring Boot 2正常工作时出现此错误。

在proguard.conf中添加-dontusemixedcaseclassnames可以解决该问题。

答案 17 :(得分:0)

在我们的例子中,我们在 .properties 文件中有一些新图像不需要的额外行。

spring.jpa.properties.hibernate.cache.use_second_level_cache=true

显然没有那个实体它试图加载什么。

答案 18 :(得分:0)

如果没有任何效果,那么我有一个解决方案 @Access(value=AccessType.FIELD) 在使用@Entity 之后在模型类下添加此行,然后在定义 id 时在类和类之后添加,并且所有时间都在使用上面的行。

答案 19 :(得分:0)

就我而言,问题是多方面的并且与 AWS 相关:

  1. @Tareq Islam 指出在 application.properties 中设置方言有帮助。我用于 MySQL 5.6:

    spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL55Dialect

  2. 此后的第二个问题是由于 SSL 连接加密的更改,JDBC 无法连接到服务器。我在

    的帮助下修复了它

SSLHandShakeException No Appropriate Protocol

但我需要通过设置为 /etc/java-11-openjdk/security/java.security 来启用 TLS1.0

jdk.tls.disabledAlgorithms=SSLv3, RC4, DES, MD5withRSA, DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL

答案 20 :(得分:0)

就我而言,我已在 application.properties 文件中将 ddl-auto 设置为验证

spring.jpa.hibernate.ddl-auto=validate

这里,当属性 hibernate.hbm2ddl.auto 设置为验证时会出现问题。设置为 none 时一切正常。我认为验证器没有考虑到当主键被定义为 GENERATED BY DEFAULT AS IDENTITY 时。

答案 21 :(得分:0)

就我而言,我在 application.properties 中添加以下行 ,问题出在 Oracle 11g DB Driver

function One() {
  return new Promise(resolve => setTimeout(resolve, 500, 42))
}

async function Two(){
  console.log("Calling One()...")
  let ret = await One();
  console.log("One() returned:", ret)
}

Two()
    

答案 22 :(得分:0)

我已经jdk-12.0.2.jdk,找到了解决问题的方法,将依赖项添加到pom.xml:

<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.javassist/javassist -->
<dependency>
    <groupId>org.javassist</groupId>
    <artifactId>javassist</artifactId>
    <version>3.25.0-GA</version>
</dependency>

答案 23 :(得分:0)

就我而言,这是由于Intellij IDEA默认将Java 11设置为默认项目SDK,但是该项目是用Java 8实现的。 我在文件->项目结构->项目(在项目设置中)中更改了“ Project SDK”

答案 24 :(得分:0)

我通过将Spring依赖版本从2.0.4更新到2.1.6解决了我的问题

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.4.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
</parent>

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.6.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
</parent>

答案 25 :(得分:0)

添加此依赖项后,我的错误已解决。

<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-validator -->
    <dependency>
        <groupId>org.hibernate.validator</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>6.0.16.Final</version>
    </dependency>

答案 26 :(得分:0)

我通过在模型中添加可序列化的工具解决了这个问题。

@Entity
@Table(name="Model_Rest")
@IdClass(Model_Rest.class)
public class Model_Rest implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    /**
     * 
     */
    //@GeneratedValue(strategy = GenerationType.AUTO)
    //@Column(columnDefinition="id")

    @Id
    private String login;
    @Id
    private String password;




    @Autowired
    public String getLogin() {
        return login;
    }

    @Autowired
    public void setLogin(String login) {
        this.login = login;
    }

    @Autowired
    public String getPassword() {
        return password;
    }

    @Autowired
    public void setPassword(String password) {
        this.password = password;
    }

    public Model_Rest() {
        // TODO Auto-generated constructor stub
    }

    public Model_Rest(String login, String password) {
        this.login = login;
        this.password = password;
    }

    @Override
    public String toString() {
        return "Model_Rest [login=" + login + ", password=" + password + "]";
    }
  }

答案 27 :(得分:0)

如果您使用的是JDK 1.8.0_201或最新版本,请尝试使用较旧的JDK。

我与JDK1.8.0_201有相同的问题,但是它与JDK1.8.0_101一起工作,没有任何代码更改。

答案 28 :(得分:0)

使用@Id为我工作。否则它将抛出错误,这取决于您的实体类或存储库中是否缺少任何内容

答案 29 :(得分:0)

问题可能是由于程序包冲突引起的。 当您在实体中使用@Id注释时,它可能会使用Spring框架的@Id;但是,它必须使用持久性API的@Id注释。

因此在实体中使用@javax.persistence.Id注释。

答案 30 :(得分:0)

我能够通过将最大池大小值从1更改为2来解决问题

spring.datasource.hikari.maximum池大小= 2

答案 31 :(得分:-1)

这可能与项目设置无关。 我收到此错误,因为我忘记了启动数据库服务器。 因此,请确保您的数据库一切正常。 (例如,我可以使用MySQL Workbench检查MySQL80服务器)

答案 32 :(得分:-1)

我遇到了类似的错误。该错误不会更早出现,但是最近我重新安装了oracle db并将实例名称从'xe'更改为'orcl',但是忘记在属性文件中更改以下代码:

spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:***xe***
spring.datasource.username=system
spring.datasource.password=manager

一旦我将其从“ xe”更改为“ orcl”,一切都很好。

答案 33 :(得分:-2)

尝试添加以下依赖项。

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
   <groupId>com.h2database</groupId>
   <artifactId>h2</artifactId>
</dependency>