![[name=Redis, majorVersion=6];用户必须注册解析器或明确设置“hibernate.dialect”](https://linux22.com/image/791764/%5Bname%3DRedis%2C%20majorVersion%3D6%5D%EF%BC%9B%E7%94%A8%E6%88%B7%E5%BF%85%E9%A1%BB%E6%B3%A8%E5%86%8C%E8%A7%A3%E6%9E%90%E5%99%A8%E6%88%96%E6%98%8E%E7%A1%AE%E8%AE%BE%E7%BD%AE%E2%80%9Chibernate.dialect%E2%80%9D.png)
我有问这个问题已经在 stackoverflow 上出现过了,但我觉得这个问题更适合在这里。抱歉重复发帖。
在 wildfly 中成功创建 redis 数据源后,我现在正尝试从我的 spring 项目连接到 redis。我对 还很陌生Spring
,自然而然地遇到了一些问题。
我的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 https://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.7.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>MY_GRP_ID</groupId>
<artifactId>MAI</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>NAME</name>
<description>DESC</description>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!--deploy.wildfly.host>XXX</deploy.wildfly.host-->
<deploy.wildfly.host>XXX</deploy.wildfly.host>
<deploy.wildfly.port>XXX</deploy.wildfly.port>
<deploy.wildfly.username>XXX</deploy.wildfly.username>
<deploy.wildfly.password>XXX</deploy.wildfly.password>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</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.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- logging framework -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<!--dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</dependency-->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</dependency>
<!-- logging end -->
<!-- GRAPH QL -->
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-spring-boot-starter</artifactId>
<version>5.0.2</version>
</dependency>
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java</artifactId>
<version>18.0</version>
</dependency>
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java-tools</artifactId>
<version>5.2.4</version>
</dependency>
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java-servlet</artifactId>
<version>6.1.3</version>
</dependency>
<!-- GRAPH QL END-->
<!--dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>2.7.2</version>
</dependency-->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>2.3.3.RELEASE</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>5.0.2</version>
<type>jar</type>
</dependency>
</dependencies>
<build>
<plugins>
<!--plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin-->
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>2.0.2.Final</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
<configuration>
<filename>${project.build.finalName}.war</filename>
<hostname>${deploy.wildfly.host}</hostname>
<port>${deploy.wildfly.port}</port>
<username>${deploy.wildfly.username}</username>
<password>${deploy.wildfly.password}</password>
</configuration>
</plugin>
</plugins>
</build>
笔记:这是一个具有多个依赖项的大型项目。
我已经创建了一个Student.java
import org.springframework.data.redis.core.RedisHash;
import java.io.Serializable;
@RedisHash("Student")
public class Student implements Serializable {
private long id;
private String name;
//boilerplate constructor, setter and getter
}
我还创建了一个StudentRepository.java
import org.springframework.data.repository.CrudRepository;
public interface StudentRepository extends CrudRepository<Student, Long> {}
到目前为止一切顺利。我构建了war
并在 wildfly 中部署。在 中server.log
,我得到了以下输出
2023-12-21 09:32:34,915 INFO [org.springframework.data.repository.config.RepositoryConfigurationDelegate] (ServerService Thread Pool -- 393) Finished Spring Data repository scanning in 55 ms. Found 2 JPA repository interfaces.
2023-12-21 09:32:34,943 INFO [org.springframework.data.repository.config.RepositoryConfigurationDelegate] (ServerService Thread Pool -- 393) Finished Spring Data repository scanning in 6 ms. Found 1 Redis repository interfaces.
2023-12-21 09:32:34,928 INFO [org.springframework.data.repository.config.RepositoryConfigurationDelegate] (ServerService Thread Pool -- 393) Multiple Spring Data modules found, entering strict repository configuration mode!
2023-12-21 09:32:34,929 INFO [org.springframework.data.repository.config.RepositoryConfigurationDelegate] (ServerService Thread Pool -- 393) Bootstrapping Spring Data Redis repositories in DEFAULT mode.
2023-12-21 09:32:34,943 INFO [org.springframework.data.repository.config.RepositoryConfigurationDelegate] (ServerService Thread Pool -- 393) Finished Spring Data repository scanning in 6 ms. Found 1 Redis repository interfaces.
2023-12-21 09:32:35,241 INFO [io.undertow.servlet] (ServerService Thread Pool -- 393) Initializing Spring embedded WebApplicationContext
2023-12-21 09:32:35,241 INFO [org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext] (ServerService Thread Pool -- 393) Root WebApplicationContext: initialization completed in 875 ms
2023-12-21 09:32:35,488 INFO [org.hibernate.jpa.internal.util.LogHelper] (ServerService Thread Pool -- 393) HHH000204: Processing PersistenceUnitInfo [name: default]
2023-12-21 09:32:35,529 INFO [org.hibernate.Version] (ServerService Thread Pool -- 393) HHH000412: Hibernate ORM core version 5.6.9.Final
2023-12-21 09:32:35,667 INFO [org.hibernate.annotations.common.Version] (ServerService Thread Pool -- 393) HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2023-12-21 09:32:35,772 WARN [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator] (ServerService Thread Pool -- 393) HHH000342: Could not obtain connection to query metadata: org.hibernate.HibernateException: Unable to determine Dialect to use [name=Redis, majorVersion=6]; user must register resolver or explicitly set 'hibernate.dialect'
在互联网上搜索后hibernate.dialect
,我发现需要hibernate.cfg.xml
在resources
目录中创建以下内容
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.ogm.datastore.redis.RedisHashDialect</property>
</session-factory>
</hibernate-configuration>
但dialect issue
遗留问题。我不知道现在该怎么办。任何帮助都将不胜感激。
笔记:抱歉,这篇文章太长了,我已尽力写得尽可能详细。