我正在尝试使用 spring boot jpa 数据源使用 AWS athena。
我尝试使用给定的属性设置数据源。
spring.datasource.driver-class-name=com.amazonaws.athena.jdbc.AthenaDriver
spring.datasource.url=jdbc:awsathena://athena.us-east-1.amazonaws.com:443/default
spring.datasource.username=*****
spring.datasource.password=***
spring.datasource.tomcat.connectionProperties=s3_staging_dir=*****
我低于异常
Caused by:org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.JpaVendorAdapter]: Factory method 'jpaVendorAdapter' threw exception; nested exception is java.lang.IllegalArgumentException: URL must start with 'jdbc'
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(Constructo`enter code here`rResolver.java:588) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
... 51 common frames omitted
Caused by: java.lang.IllegalArgumentException: URL must start with 'jdbc'
at org.springframework.util.Assert.isTrue(Assert.java:92) ~[spring-core-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.boot.jdbc.DatabaseDriver.fromJdbcUrl(DatabaseDriver.java:268) ~[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.DatabaseLookup.getDatabase(DatabaseLookup.java:73) ~[spring-boot-autoconfigure-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.JpaProperties.determineDatabase(JpaProperties.java:139) ~[spring-boot-autoconfigure-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.jpaVendorAdapter(JpaBaseConfiguration.java:105) ~[spring-boot-autoconfigure-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration$$EnhancerBySpringCGLIB$$720f8624.CGLIB$jpaVendorAdapter$4(<generated>) ~[spring-boot-autoconfigure-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration$$EnhancerBySpringCGLIB$$720f8624$$FastClassBySpringCGLIB$$9766cf.invoke(<generated>) ~[spring-boot-autoconfigure-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.7.RELEASE.jar:4.3.7.RELEASE]
最佳答案
默认情况下,Spring boot 会自动检测哪个 Hibernate Dialect基于从 JDBC 驱动程序检索到的 Datasource 的元数据来使用。
此错误是由于 Athena JDBC 驱动程序无法获取相关元数据。不确定为什么会失败,但您可以绕过此检测并通过声明 JpaVendorAdapter
来明确声明自己要使用哪种 Hibernate 方言| bean 角,扁 bean :
@Bean
public JpaVendorAdapter jpaVendorAdapter(JpaProperties properties) {
AbstractJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
adapter.setShowSql(properties.isShowSql());
adapter.setGenerateDdl(properties.isGenerateDdl());
return adapter;
}
我保留所有默认行为,但只是禁用自动检测方言
并在
application.properties
中定义方言:spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.XXXXXX
但关键是我怀疑 Athena 是否可以与 Hibernate 一起使用,因为我找不到 Athena 的现有方言。所以我的建议是:
关于amazon-web-services - 通过 JPA spring boot 访问 AWS athena,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43089385/