我尝试并且未能使用游戏2.5。
我的控制器:
public class HomeController extends Controller {
private JPAApi db;
@Inject
public HomeController(JPAApi api) {
this.db = api;
}
public Result index(String name) {
return ok(views.html.index.render("hello", name, Collections.singletonList("world")));
}
}
我的conf \ META-INF \ persistence.xml
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="readwritePU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<non-jta-data-source>ReadWriteDS</non-jta-data-source>
<properties>
<property name="hibernate.connection.isolation" value="1" />
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL94Dialect" />
<property name="hibernate.cache.use_second_level_cache" value="false" />
<property name="hibernate.cache.use_query_cache" value="false" />
</properties>
</persistence-unit>
</persistence>
我的conf \ application.conf
jpa.default=readwritePU
db {
#pool = "hikaricp"
default.driver = org.postgresql.Driver
default.url = "jdbc:postgresql://127.0.0.1:5432/mydbname"
default.username = "postgres"
default.password = "123456"
#default = "default"
default.jndiName=ReadWriteDS
}
上面的application.conf中启用了池配置键的错误和错误:
No configuration setting found for key 'pool'
Error in custom provider, com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'pool'
while locating play.api.db.DBApiProvider
while locating play.api.db.DBApi
for field at play.api.db.NamedDatabaseProvider.dbApi(DBModule.scala:80)
while locating play.api.db.NamedDatabaseProvider
at com.google.inject.util.Providers$GuicifiedProviderWithDependencies.initialize(Providers.java:149)
at play.api.db.DBModule$$anonfun$namedDatabaseBindings$1.apply(DBModule.scala:34):
Binding(interface play.api.db.Database qualified with QualifierInstance(@play.db.NamedDatabase(value=default)) to ProviderTarget(play.api.db.NamedDatabaseProvider@7af4d3bc)) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1)
Caused by: com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'pool'
pool has type STRING rather than OBJECT
Error in custom provider, com.typesafe.config.ConfigException$WrongType: application.conf @ file:/E:/workspace2/coup/target/scala-2.11/classes/application.conf: 344: pool has type STRING rather than OBJECT
while locating play.api.db.DBApiProvider
while locating play.api.db.DBApi
for parameter 0 at play.db.DefaultDBApi.<init>(DefaultDBApi.java:27)
at play.db.DefaultDBApi.class(DefaultDBApi.java:27)
while locating play.db.DefaultDBApi
while locating play.db.DBApi
for field at play.db.DBModule$NamedDatabaseProvider.dbApi(DBModule.java:61)
while locating play.db.DBModule$NamedDatabaseProvider
at com.google.inject.util.Providers$GuicifiedProviderWithDependencies.initialize(Providers.java:149)
at play.db.DBModule.bindings(DBModule.java:40):
Binding(interface play.db.Database qualified with QualifierInstance(@play.db.NamedDatabase(value=default)) to ProviderTarget(play.db.DBModule$NamedDatabaseProvider@3ec40700)) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1)
Caused by: com.typesafe.config.ConfigException$WrongType: application.conf @ file:/E:/workspace2/coup/target/scala-2.11/classes/application.conf: 344: pool has type STRING rather than OBJECT
我尝试了很多不同的选项和组合,我没有想法。谷歌甚至不知道错误。播放只是停止工作,我必须重新启动它。
答案 0 :(得分:2)
尝试
jpa.default=readwritePU
db {
default {
hikaricp {
dataSourceClassName=org.postgresql.ds.PGSimpleDataSource
dataSource {
serverName = localhost
databaseName = "mydbname"
user = "postgres"
password = "123456"
}
}
jndiName=ReadWriteDS
}
}