问题
In the past I have used Slick to access a Vertica database in a server. I recently upgraded my version of Slick from 2.0 to 3.1. Since the upgrade, I am encountering an error (stack trace below). The error indicates that the slick driver cannot be found.
According to the Slick 3.2.1 docs, "Other SQL databases can be accessed right away with a reduced feature set".
What I am wondering is - Is it still possible to use an "Other" type of database from those directly supported by slick? If so, how?
My database config is:
slick.dbs.default.driver="slick.driver.JdbcDriver"
slick.dbs.default.db.driver="com.vertica.jdbc.Driver"
slick.dbs.default.db.url=${some.url}
slick.dbs.default.db.user=${some.user}
slick.dbs.default.db.password=${some.pw}
Please note that thanks to this Stack Overflow response, I have also tried each of the following to replace the first line in the config:
slick.dbs.default.driver="slick.driver.JdbcDriver$"
slick.dbs.default.driver="slick.driver.JdbcDriver$class"
slick.dbs.default.driver=slick.driver.JdbcDriver
I also have in my sbt file:
libraryDependencies ++= Seq(
"com.vertica" % "vertica-jdbc" % "7.0.1",
"com.typesafe.play" %% "play-slick" % "2.0.0")
Note that play-slick uses slick 3.1.0.
Full stack trace:
[ERROR] [10/07/2016 16:43:52.336] [p.a.d.s.DefaultSlickApi] [*] Failed to create Slick database config for key default.
slick.SlickException: Error getting instance of Slick driver "slick.driver.JdbcDriver"
at slick.backend.DatabaseConfig$.forConfig(DatabaseConfig.scala:65)
at play.api.db.slick.DefaultSlickApi$DatabaseConfigFactory.create(SlickApi.scala:89)
at play.api.db.slick.DefaultSlickApi$DatabaseConfigFactory.get$lzycompute(SlickApi.scala:81)
at play.api.db.slick.DefaultSlickApi$DatabaseConfigFactory.get(SlickApi.scala:80)
at play.api.db.slick.DefaultSlickApi.dbConfig(SlickApi.scala:66)
at play.api.db.slick.NamedDatabaseConfigProvider$$anon$1.get(SlickModule.scala:59)
at utils.liger.DimensionMapper.<init>(DimensionMapper.scala:32)
at utils.liger.DimensionMapper$$FastClassByGuice$$1320fe73.newInstance(<generated>)
at com.google.inject.internal.cglib.reflect.$FastConstructor.newInstance(FastConstructor.java:40)
at com.google.inject.internal.DefaultConstructionProxyFactory$1.newInstance(DefaultConstructionProxyFactory.java:61)
at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:105)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:267)
at com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:38)
at com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:62)
at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:104)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:267)
at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1103)
at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
at com.google.inject.internal.SingletonScope$1.get(SingletonScope.java:145)
at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41)
at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:205)
at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:199)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092)
at com.google.inject.internal.InternalInjectorCreator.loadEagerSingletons(InternalInjectorCreator.java:199)
at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:180)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:110)
at com.google.inject.Guice.createInjector(Guice.java:96)
at com.google.inject.Guice.createInjector(Guice.java:84)
at play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:181)
at play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:123)
at play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21)
at play.core.server.ProdServerStart$.start(ProdServerStart.scala:47)
at play.core.server.ProdServerStart$.main(ProdServerStart.scala:22)
at play.core.server.ProdServerStart.main(ProdServerStart.scala)
Caused by: java.lang.InstantiationException: slick.driver.JdbcDriver
at java.lang.Class.newInstance(Class.java:427)
at slick.backend.DatabaseConfig$.forConfig(DatabaseConfig.scala:63)
... 36 common frames omitted
Caused by: java.lang.NoSuchMethodException: slick.driver.JdbcDriver.<init>()
at java.lang.Class.getConstructor0(Class.java:3082)
at java.lang.Class.newInstance(Class.java:412)
... 37 common frames omitted
If I instead use:
slick.dbs.default.driver="slick.driver.JdbcDriver$"
Then:
[ERROR] [10/07/2016 16:36:07.701] [p.a.d.s.DefaultSlickApi] [*] Failed to create Slick database config for key default.
slick.SlickException: Error getting instance of Slick driver "slick.driver.JdbcDriver$"
at slick.backend.DatabaseConfig$.forConfig(DatabaseConfig.scala:65)
at play.api.db.slick.DefaultSlickApi$DatabaseConfigFactory.create(SlickApi.scala:89)
at play.api.db.slick.DefaultSlickApi$DatabaseConfigFactory.get$lzycompute(SlickApi.scala:81)
at play.api.db.slick.DefaultSlickApi$DatabaseConfigFactory.get(SlickApi.scala:80)
at play.api.db.slick.DefaultSlickApi.dbConfig(SlickApi.scala:66)
at play.api.db.slick.NamedDatabaseConfigProvider$$anon$1.get(SlickModule.scala:59)
at controllers.liger.AwdAutomation.<init>(AwdAutomation.scala:43)
at controllers.liger.AwdAutomation$$FastClassByGuice$$64e5b177.newInstance(<generated>)
at com.google.inject.internal.cglib.reflect.$FastConstructor.newInstance(FastConstructor.java:40)
at com.google.inject.internal.DefaultConstructionProxyFactory$1.newInstance(DefaultConstructionProxyFactory.java:61)
at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:105)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:267)
at com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:38)
at com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:62)
at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:104)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:267)
at com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:38)
at com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:62)
at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:104)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:267)
at com.google.inject.internal.InjectorImpl$2$1.call(InjectorImpl.java:1016)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1103)
at com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1012)
at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1051)
at play.api.inject.guice.GuiceInjector.instanceOf(GuiceInjectorBuilder.scala:405)
at play.api.inject.RoutesProvider$$anonfun$2.apply(BuiltinModule.scala:82)
at play.api.inject.RoutesProvider$$anonfun$2.apply(BuiltinModule.scala:82)
at scala.Option.fold(Option.scala:158)
at play.api.inject.RoutesProvider.get$lzycompute(BuiltinModule.scala:82)
at play.api.inject.RoutesProvider.get(BuiltinModule.scala:78)
at play.api.inject.RoutesProvider.get(BuiltinModule.scala:77)
at com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:81)
at com.google.inject.internal.BoundProviderFactory.provision(BoundProviderFactory.java:72)
at com.google.inject.internal.ProviderInternalFactory.circularGet(ProviderInternalFactory.java:61)
at com.google.inject.internal.BoundProviderFactory.get(BoundProviderFactory.java:62)
at com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:38)
at com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:62)
at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:104)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:267)
at com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:38)
at com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:62)
at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:104)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:267)
at com.google.inject.internal.FactoryProxy.get(FactoryProxy.java:56)
at com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:38)
at com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:62)
at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:104)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:267)
at com.google.inject.internal.FactoryProxy.get(FactoryProxy.java:56)
at com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:38)
at com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:62)
at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:104)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:267)
at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1103)
at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
at com.google.inject.internal.SingletonScope$1.get(SingletonScope.java:145)
at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41)
at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:205)
at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:199)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092)
at com.google.inject.internal.InternalInjectorCreator.loadEagerSingletons(InternalInjectorCreator.java:199)
at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:180)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:110)
at com.google.inject.Guice.createInjector(Guice.java:96)
at com.google.inject.Guice.createInjector(Guice.java:84)
at play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:181)
at play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:123)
at play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21)
at play.core.server.ProdServerStart$.start(ProdServerStart.scala:47)
at play.core.server.ProdServerStart$.main(ProdServerStart.scala:22)
at play.core.server.ProdServerStart.main(ProdServerStart.scala)
Caused by: java.lang.ClassNotFoundException: slick.driver.JdbcDriver$
at java.lang.ClassLoader.findClass(ClassLoader.java:530)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at slick.util.ClassLoaderUtil$$anon$1.loadClass(ClassLoaderUtil.scala:12)
at slick.backend.DatabaseConfig$.forConfig(DatabaseConfig.scala:62)
... 78 common frames omitted
回答1:
With Slick 3.0 the generic jdbc driver slick.driver.JdbcDriver$
has been deprecated (as you can see from source) and then removed in version 3.1 (this explains the error you are seeing)
By now, with slick 3.2, other databases can be supported with a custom implementation of the trait slick.jdbc.JdbcProfile
来源:https://stackoverflow.com/questions/39927224/how-to-use-a-non-supported-database-in-slick-3-1