简体   繁体   English

如何在Glassfish上部署Play Framework 2.4应用程序并阅读application.conf

[英]How to deploy play framework 2.4 application on glassfish and read application.conf

I tried to deploy play framework 2.4 application on glassfish. 我试图在glassfish上部署play framework 2.4应用程序。 I used maven play2 plugin and made war file with the following instruction. 我使用了maven play2插件,并按照以下说明制作了war文件。

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

After that, I tried to deploy my war from glassfish console, but it returned the following error. 之后,我尝试从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.

And MyBatisModule is like this. 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();
        }
    }

I think the application can't read application.conf that containts DB setting. 我认为应用程序无法读取包含数据库设置的application.conf。 But I'm not sure. 但是我不确定。

Could you give me any advices? 你能给我什么建议吗?

Update 2015/01/13 更新2015/01/13

I disabled "Implicit CDI" option on glassfish console when I deployed application. 部署应用程序时,我在glassfish控制台上禁用了“隐式CDI”选项。 I don't get the first error now, but I get another error... 我现在没有第一个错误,但我又遇到了一个错误...

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

My conf/application.conf is here: 我的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

And it works on local environment. 它可以在本地环境下工作。 I think glassfish can't read application.conf in war file. 我认为glassfish无法读取war文件中的application.conf。

I'm sorry. 对不起。 Could you give me the advice again? 您能再给我提建议吗?

Update 2015/01/14 更新2015/01/14

The following is the part of full log. 以下是完整日志的一部分。

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)

Some thoughts (it should be comment, but I cannot write comments on SO yet). 一些想法(应该是评论,但是我还不能写评论)。

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

  2. Does war file contain JDBC driver? war文件是否包含JDBC驱动程序?

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

My problem cause is that: 我的问题原因是:

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 https://www.playframework.com/documentation/2.4.x/Migration24#JDBC-connection-pool

After I add the following setting on application.conf, it works. 在application.conf上添加以下设置后,它可以工作。 (This sql is for Oracle DB.) (此sql适用于Oracle DB。)

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

Thank you for your help! 谢谢您的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM