如何在glassfish上部署play framework 2.4应用程序并阅读application.conf

时间:2016-01-12 08:37:17

标签: java playframework glassfish glassfish-4 playframework-2.4

我尝试在glassfish上部署play framework 2.4应用程序。 我使用maven play2插件并使用以下指令制作war文件。

https://play2-maven-plugin.github.io/play2-maven-plugin/1.0.0-beta4/war-packaging.html

之后,我尝试从glassfish控制台部署我的战争,但它返回了以下错误。

  Error occurred during deployment: Exception while loading the app : 
  CDI deployment failure:Exception List with 3 exceptions: 
  Exception 0 : org.jboss.weld.exceptions.DeploymentException: 
  WELD-001408: Unsatisfied dependencies for type Environment with qualifiers @Default
   at injection point [BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedConstructor] @Inject public play.api.db.BoneConnectionPool(Environment)
   at play.api.db.BoneConnectionPool.<init>(BoneConnectionPool.java:0)
   at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:370)
   at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:291)
   at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:134)
   at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:165)
   at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:529)
   at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:515)
   at org.jboss.weld.bootst .... msg.seeServerLog


  Error occurred during deployment: Exception while loading the app : 
  CDI deployment failure:
  WELD-001408: Unsatisfied dependencies for type Database with qualifiers @Default 
   at injection point [BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedConstructor] @Inject public modules.MyBatisModule$PlayDataSourceProvider(Database) 
   at modules.MyBatisModule$PlayDataSourceProvider.<init>(PlayDataSourceProvider.java:0) . 
   Please see server.log for more details.

MyBatisModule就像这样。

public class MyBatisModule extends org.mybatis.guice.MyBatisModule {

    @Override
    protected void initialize() {
        environmentId("development");
        bindConstant().annotatedWith(Names.named("mybatis.configuration.failFast")).to(true);
        bindDataSourceProviderType(PlayDataSourceProvider.class);
        bindTransactionFactoryType(JdbcTransactionFactory.class);
        addMapperClasses();
    }

    @Singleton
    public static class PlayDataSourceProvider implements Provider<DataSource> {
        final Database db;

        @Inject
        public PlayDataSourceProvider(final Database db) {
            this.db = db;
        }

        public DataSource get() {
            return db.getDataSource();
        }
    }

我认为应用程序无法读取包含数据库设置的application.conf。但我不确定。

你能给我任何建议吗?

更新2015/01/13

我禁用了#34;隐含的CDI&#34;我部署应用程序时在glassfish控制台上的选项。 我现在没有收到第一个错误,但是我收到了另一个错误......

Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: 
ContainerBase.addChild: start: org.apache.catalina.LifecycleException: com.google.inject.CreationException: 
Unable to create injector, see the following errors: 
1) Error in custom provider, Configuration error: Configuration error
[Cannot connect to database [default]] while locating play.api.db.DBApiProvider while locating play.api.db.DBApi for parameter 0 
at play.db.DefaultDBApi.<init>(DefaultDBApi.java:28) 
at play.db.DefaultDBApi.class(DefaultDBApi.java:28) 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 QualifierInstanc .... msg.seeServerLog

我的conf / application.conf在这里:

db.default.driver=oracle.jdbc.driver.OracleDriver
db.default.url="jdbc:oracle:thin:@url..."
db.default.username=username
db.default.password=password

它适用于当地环境。 我认为glassfish无法在war文件中读取application.conf。

对不起。你能再次给我一些建议吗?

更新2015/01/14

以下是完整日志的一部分。

Caused by: Configuration error: Configuration error[Exception during pool initialization]
    at play.api.Configuration$.configError(Configuration.scala:178)
    at play.api.PlayConfig.reportError(Configuration.scala:1048)
    at play.api.db.HikariCPConnectionPool.create(HikariCPModule.scala:69)
    at play.api.db.PooledDatabase.createDataSource(Databases.scala:199)
    at play.api.db.DefaultDatabase.dataSource$lzycompute(Databases.scala:124)
    at play.api.db.DefaultDatabase.dataSource(Databases.scala:122)
    at play.api.db.DefaultDatabase.getConnection(Databases.scala:143)
    at play.api.db.DefaultDatabase.getConnection(Databases.scala:139)
    at play.api.db.DefaultDBApi$$anonfun$connect$1.apply(DefaultDBApi.scala:44)
    ... 130 more
Caused by: com.zaxxer.hikari.pool.PoolInitializationException: Exception during pool initialization
    at com.zaxxer.hikari.pool.BaseHikariPool.initializeConnections(BaseHikariPool.java:542)
    at com.zaxxer.hikari.pool.BaseHikariPool.<init>(BaseHikariPool.java:171)
    at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:60)
    at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:48)
    at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:80)
    at play.api.db.HikariCPConnectionPool$$anonfun$1.apply(HikariCPModule.scala:58)
    at play.api.db.HikariCPConnectionPool$$anonfun$1.apply(HikariCPModule.scala:54)
    at scala.util.Try$.apply(Try.scala:191)
    at play.api.db.HikariCPConnectionPool.create(HikariCPModule.scala:54)
    ... 136 more
Caused by: java.sql.SQLException: JDBC4 Connection.isValid() method not supported, connection test query must be configured
    at com.zaxxer.hikari.pool.BaseHikariPool.addConnection(BaseHikariPool.java:441)
    at com.zaxxer.hikari.pool.BaseHikariPool.initializeConnections(BaseHikariPool.java:540)
    ... 144 more

3) Error in custom provider, java.lang.NullPointerException
  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@34850279)) (vi
a modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1)
  while locating play.db.Database annotated with @play.db.NamedDatabase(value=default)

2 个答案:

答案 0 :(得分:0)

一些想法(应该是评论,但我还不能在SO上发表评论)。

  1. 如果您的application.conf文件位于WEB-INF/classes目录中,则应找到该文件(更多信息 - https://www.playframework.com/documentation/2.4.x/ProductionConfiguration#Specifying-an-alternate-configuration-file)。

  2. war文件是否包含JDBC驱动程序?

  3. 也许您应该配置JNDI - https://www.playframework.com/documentation/2.4.x/ScalaDatabaseOthers#Exposing-the-datasource-through-JNDI

答案 1 :(得分:0)

我的问题原因是:

Caused by: java.sql.SQLException: JDBC4 Connection.isValid() method not supported, connection test query must be configured

https://www.playframework.com/documentation/2.4.x/Migration24#JDBC-connection-pool

在application.conf上添加以下设置后,它可以正常工作。 (此sql适用于Oracle DB。)

db.default.hikaricp.connectionTestQuery="SELECT 1 FROM DUAL"

感谢您的帮助!