Hibernate-spatial jpa with mysql 和 Spring boot 1.5.7 不工作

Hibernate-spatial jpa with myql and Spring boot 1.5.7 not working

我想在 mysql 和 spring 启动时使用 hibernate spatial。我试过但失败了。 application.properties 文件如下

spring.datasource.url=jdbc:mysql://localhost:3306/tour_management
spring.datasource.username=root
spring.datasource.password=admin
endpoints.actuator.enabled=true
endpoints.info.enabled=true

spring.jpa.properties.hibernate.dialect = 
org.hibernate.spatial.dialect.mysql.MySQLSpatial5InnoDBDialect
spring.jpa.database-platform = 
org.hibernate.spatial.dialect.mysql.MySQLSpatial5InnoDBDialect



@Data
@Entity(name = "Place")
public class PlaceEntity extends BaseEntity {
@Id
@GeneratedValue
@Column(name = "ID")
private long id;
@Column(name = "NAME")
private String name;
@Column(name = "CODE")
private String code;
@Column(name = "LONGITUDE")
private Double longitude;
@Column(name = "LATITUDE")
private Double latitude;

@Column(name = "LOCATION",columnDefinition = "geometry(Point,4326)")
private Point location;
}

但是部署时出现异常

buildscript {
ext {
    springBootVersion = '1.5.7.RELEASE'
}
repositories {
    mavenCentral()
    maven {
        url "http://www.hibernatespatial.org/repository"
    }
}
dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-
plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
group = 'com.fm'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
maven {
    url "http://www.hibernatespatial.org/repository"
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('mysql:mysql-connector-java')
compile('org.projectlombok:lombok:1.14.8')
compile('org.springframework.boot:spring-boot-starter-web')
compile('com.vividsolutions:jts:1.13')
testCompile('org.springframework.boot:spring-boot-starter-test')
}

原因:org.hibernate.boot.registry.selector.spi.StrategySelectionException:无法将名称 [org.hibernate.spatial.dialect.mysql.MySQLSpatial5InnoDBDialect] 解析为策略 [org.hibernate.dialect.Dialect] 在 org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor(StrategySelectorImpl.java:113) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]

是否有版本问题????

如果我们在运行时匹配您的异常:

Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.spatial.dialect.mysql.MySQLSpatial5InnoDBDialect] as strategy [org.hibernate.dialect.Dialect] at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor(StrategySelectorImpl.java:113) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]

StrategySelectorImpl的源代码:

@Override
    @SuppressWarnings("unchecked")
    public <T> Class<? extends T> selectStrategyImplementor(Class<T> strategy, String name) {
        final Map<String,Class> namedStrategyImplementorMap = namedStrategyImplementorByStrategyMap.get( strategy );
        if ( namedStrategyImplementorMap != null ) {
            final Class registered = namedStrategyImplementorMap.get( name );
            if ( registered != null ) {
                return (Class<T>) registered;
            }
        }

        try {
            return classLoaderService.classForName( name );
        }
        catch (ClassLoadingException e) {
            throw new StrategySelectionException(
                    "Unable to resolve name [" + name + "] as strategy [" + strategy.getName() + "]"
            );
        }
    }

我们了解到 org.hibernate.spatial.dialect.mysql.MySQLSpatial5InnoDBDialect class 无法由 class 加载程序加载。它可能不在 class 路径中。

我想你应该添加与你的 Hibernate 版本匹配的 hibernate 空间依赖性。