本文介绍了没有绑定play.db.Database的实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用hikaricp时,我无法访问db

Im having problem accessing db, when using hikaricp

这是我的reference.conf

play {

  modules {
    enabled += "play.api.db.DBModule"
    enabled += "play.api.db.HikariCPModule"
  }

  # Database configuration
  db {
    # The name of the configuration item from which to read database config.
    # So, if set to db, means that db.default is where the configuration for the
    # database named default is found.
    config = "db"

    # The name of the default database, used when no database name is explicitly
    # specified.
    default = "default"

    # The default connection pool.
    # Valid values are:
    #  - default - Use the default connection pool provided by the platform (HikariCP)
    #  - hikaricp - Use HikariCP
    #  - bonecp - Use BoneCP
    #  - A FQCN to a class that implements play.api.db.ConnectionPool
    pool = "default"

    # The prototype for database configuration
    prototype = {

      # The connection pool for this database.
      # Valid values are:
      #  - default - Delegate to play.db.pool
      #  - hikaricp - Use HikariCP
      #  - bonecp - Use BoneCP
      #  - A FQCN to a class that implements play.api.db.ConnectionPool
      pool = "default"

      # The database driver
      driver = null

      # The database url
      url = null

      # The username
      username = null

      # The password
      password = null

      # If non null, binds the JNDI name to this data source to the given JNDI name.
      jndiName = null

      # If it should log sql statements
      logSql = false

      # HikariCP configuration options
      hikaricp {

        # The datasource class name, if not using a URL
        dataSourceClassName = null

        # Data source configuration options
        dataSource {
        }

        # Whether autocommit should be used
        autoCommit = true

        # The connection timeout
        connectionTimeout = 30 seconds

        # The idle timeout
        idleTimeout = 10 minutes

        # The max lifetime of a connection
        maxLifetime = 30 minutes

        # If non null, the query that should be used to test connections
        connectionTestQuery = null

        # If non null, sets the minimum number of idle connections to maintain.
        minimumIdle = null

        # The maximum number of connections to make.
        maximumPoolSize = 10

        # If non null, sets the name of the connection pool. Primarily used for stats reporting.
        poolName = null

        # Sets whether or not construction of the pool should fail if the minimum number of connections
        # coludn't be created.
        initializationFailFast = true

        # Sets whether internal queries should be isolated
        isolateInternalQueries = false

        # Sets whether pool suspension is allowed.  There is a performance impact to enabling it.
        allowPoolSuspension = false

        # Sets whether connections should be read only
        readOnly = false

        # Sets whether mbeans should be registered
        registerMbeans = false

        # If non null, sets the catalog that should be used on connections
        catalog = null

        # A SQL statement that will be executed after every new connection creation before adding it to the pool
        connectionInitSql = null

        # If non null, sets the transaction isolation level
        transactionIsolation = null

        # The validation timeout to use
        validationTimeout = 5 seconds

        # If non null, sets the threshold for the amount of time that a connection has been out of the pool before it is
        # considered to have leaked
        leakDetectionThreshold = null
      }

      # BoneCP configuration options
      bonecp {

        # Whether autocommit should be used
        autoCommit = true

        # If non null, the transaction isolation level to use.
        isolation = null

        # If non null, sets the catolog to use
        defaultCatalog = null

        # Whether the database should be treated as read only
        readOnly = false

        # Whether opened statements should be automatically closed
        closeOpenStatements = true

        # The pool partition count
        partitionCount = 1

        # The maximum number of connections per partition
        maxConnectionsPerPartition = 30

        # The minimum number of connections per partition
        minConnectionsPerPartition = 5

        # The increment to acquire connections in
        acquireIncrement = 1

        # The acquire retry attempts
        acquireRetryAttempts = 10

        # The delay to wait before retrying to acquire a connection
        acquireRetryDelay = 1 second

        # The connection timeout
        connectionTimeout = 1 second

        # The idle age to expire connections
        idleMaxAge = 10 minutes

        # The maximum a connection should live for
        maxConnectionAge = 1 hour

        # Whether JMX reporting should be disabled
        disableJMX = true

        # Whether statistics should be kept
        statisticsEnabled = false

        # How frequently idle connections should be tested
        idleConnectionTestPeriod = 1 minute

        # Disable connection tracking
        disableConnectionTracking = true

        # The time limit for executing queries. 0 means no time limit.
        queryExecuteTimeLimit = 0

        # Whether the connection should be reset when closed
        resetConnectionOnClose = false

        # Whether unresolved transations should be detected
        detectUnresolvedTransactions = false

        # An SQL statement to execute to test if a connection is ok after it is created.
        # Null turns this feature off.
        initSQL = null

        # An SQL statement to execute to test if a connection is ok before giving it out of the pool.
        # Null turns this feature off.
        connectionTestStatement = null

        # Whether SQL statements should be logged
        logStatements = false
      }
    }
  }

  # Evolutions configuration
  evolutions {

    # Whether evolutions are enabled
    enabled = true

    # Database schema in which the generated evolution and lock tables will be saved to
    schema = ""

    # Whether evolution updates should be performed with autocommit or in a manually managed transaction
    autocommit = true

    # Whether locks should be used when apply evolutions.  If this is true, a locks table will be created, and will
    # be used to synchronise between multiple Play instances trying to apply evolutions.  Set this to true in a multi
    # node environment.
    useLocks = false

    # Whether evolutions should be automatically applied.  In prod mode, this will only apply ups, in dev mode, it will
    # cause both ups and downs to be automatically applied.
    autoApply = false

    # Whether downs should be automatically applied.  This must be used in combination with autoApply, and only applies
    # to prod mode.
    autoApplyDowns = false

    # Db specific configuration. Should be a map of db names to configuration in the same format as this.
    db {

    }
  }
}

这是我的application.conf

play.db.pool=hikaricp
play.db.prototype.hikaricp.driver=com.mysql.jdbc.Driver
play.db.prototype.hikaricp.url="jdbc:mysql://192.168.1.37/mydb?zeroDateTimeBehavior=convertToNull"
play.db.prototype.hikaricp.username=biboy
play.db.prototype.hikaricp.password="biboy"

play.db.prototype.hikaricp.maximumPoolSize            = 5
play.db.prototype.hikaricp.minimumIdle                = 0
play.db.prototype.hikaricp.maxLifetime                = 2 minutes
play.db.prototype.hikaricp.connectionTestQuery        = "/* ping */ SELECT 1"
play.db.prototype.hikaricp.leakDetectionThreshold     = 30 seconds
play.db.prototype.hikaricp.idleTimeout                = 60 seconds
play.db.prototype.hikaricp.connectionTimeout          = 3 minutes
play.db.prototype.hikaricp.validationTimeout          = 1 minute

该错误始终表明

1) No implementation for play.db.Database was bound.
[info]   while locating play.db.Database
[info]     for field at com.spingine.base.BaseController.database(BaseController.java:12)
[info]   while locating com.spingine.controllers.CreateTaskItinerary
[info]     for parameter 3 at router.Routes.<init>(Routes.scala:88)
[info]   while locating router.Routes
[info]   while locating play.api.inject.RoutesProvider
[info]   while locating play.api.routing.Router

这就是我访问数据库的方式

And this is how I access my Database

public class AddAccount extends BaseController {
    @Inject
    Database db;
    public void add(){
     // omitted for clarity of the problem
    }
}

但是,当我使用不带hikari cp的db的默认设置时,它进行得很好,但是当我使用hikaricp时,问题就存在了.我该如何缓解这个问题?

But when I use the default setup for db without hikari cp, It goes well but when I use hikaricp the problem exists.How do i mitigate this issue?

推荐答案

我认为您在application.conf中覆盖的数据库配置是错误的.您应该设置数据库配置时不要使用hikaricp前缀:

I think your database configuration overriden in application.conf is wrong. You should set your db configuration without hikaricp prefix:

play.db.prototype.driver=com.mysql.jdbc.Driver
play.db.prototype.url="jdbc:mysql://192.168.1.37/mydb?zeroDateTimeBehavior=convertToNull"
play.db.prototype.username=*****
play.db.prototype.password=*****

这篇关于没有绑定play.db.Database的实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 20:11