application.conf文件:
default.driver = oracle.jdbc.OracleDriver
default.url = "jdbc:oracle:thin:@host_name:port/sid"
default.jndiName=""
default.username = username
default.password = "password"
但是,在执行此操作后,似乎仍然存在一个小的配置问题,因为我收到错误。我已经广泛搜索并在网上发现了许多类似的问题,但由于版本差异,他们都没有解决问题。任何帮助是极大的赞赏。这是我在尝试打开应用时收到的完整错误消息:
play.api.Configuration$$anon$1: Configuration error[Cannot connect to database [
default]]
at play.api.Configuration$.configError(Configuration.scala:154)
at play.api.Configuration.reportError(Configuration.scala:806)
at play.api.db.DefaultDBApi$$anonfun$connect$1.apply(DefaultDBApi.scala:
48)
at play.api.db.DefaultDBApi$$anonfun$connect$1.apply(DefaultDBApi.scala:
42)
at scala.collection.immutable.List.foreach(List.scala:381)
at play.api.db.DefaultDBApi.connect(DefaultDBApi.scala:42)
at play.api.db.DBApiProvider.get$lzycompute(DBModule.scala:72)
at play.api.db.DBApiProvider.get(DBModule.scala:62)
at play.api.db.DBApiProvider.get(DBModule.scala:58)
at com.google.inject.internal.ProviderInternalFactory.provision(Provider
InternalFactory.java:81)
Caused by: play.api.Configuration$$anon$1: Configuration error[Driver not found:
[oracle.jdbc.OracleDriver}]]
at play.api.Configuration$.configError(Configuration.scala:154)
at play.api.PlayConfig.reportError(Configuration.scala:996)
at play.api.db.DefaultDatabase$$anonfun$driver$1.apply(Databases.scala:1
14)
at play.api.db.DefaultDatabase$$anonfun$driver$1.apply(Databases.scala:1
08)
at scala.Option.map(Option.scala:146)
at play.api.db.DefaultDatabase.driver$lzycompute(Databases.scala:108)
at play.api.db.DefaultDatabase.driver(Databases.scala:107)
at play.api.db.DefaultDatabase.dataSource$lzycompute(Databases.scala:122
)
at play.api.db.DefaultDatabase.dataSource(Databases.scala:121)
at play.api.db.DefaultDatabase.getConnection(Databases.scala:142)
Caused by: play.api.PlayException: Cannot load Driver[Driver [oracle.jdbc.Oracle
Driver] cannot be instantiated.]
at play.utils.Reflect$.createInstance(Reflect.scala:142)
at play.api.db.DefaultDatabase$$anonfun$driver$1.apply(Databases.scala:1
10)
at play.api.db.DefaultDatabase$$anonfun$driver$1.apply(Databases.scala:1
08)
at scala.Option.map(Option.scala:146)
at play.api.db.DefaultDatabase.driver$lzycompute(Databases.scala:108)
at play.api.db.DefaultDatabase.driver(Databases.scala:107)
at play.api.db.DefaultDatabase.dataSource$lzycompute(Databases.scala:122
)
at play.api.db.DefaultDatabase.dataSource(Databases.scala:121)
at play.api.db.DefaultDatabase.getConnection(Databases.scala:142)
at play.api.db.DefaultDatabase.getConnection(Databases.scala:138)
Caused by: java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at play.utils.Reflect$.getClass(Reflect.scala:147)
at play.utils.Reflect$.createInstance(Reflect.scala:136)
at play.api.db.DefaultDatabase$$anonfun$driver$1.apply(Databases.scala:1
10)
at play.api.db.DefaultDatabase$$anonfun$driver$1.apply(Databases.scala:1
08)
at scala.Option.map(Option.scala:146)
答案 0 :(得分:1)
Play不会自动将所有数据库驱动程序都包含为项目的依赖项。如果我是正确的,只包括H2内存数据库。
您需要添加Oracle JDBC驱动程序作为项目的依赖项。 例如,通过在build.sbt中添加依赖项:
libraryDependencies += "com.oracle" % "ojdbc7" % "12.1.0.2"
但是要使其工作,您必须将Oracle Maven存储库添加到存储库列表中。请参阅Oracle Maven Repository(您需要注册,但由于您拥有Oracle数据库,您可能是这样)。
如果无法将Oracle Repository添加到项目或公司的内部存储库中,则可以下载jar并将其放在项目的/ lib目录中。这是一个非托管的依赖。