【问题标题】:How to run cbioportal tomcat war using heroku's webapp-runner.jar如何使用 heroku 的 webapp-runner.jar 运行 cbioportal tomcat 战争
【发布时间】:2016-03-16 20:14:00
【问题描述】:

我一直在学习 Heroku (https://devcenter.heroku.com/articles/java-webapp-runner) 的教程,学习如何使用 webapp-runner.jar 运行 war 文件。现在我想在 heroku 上运行 cbioportal (https://github.com/cbioportal/cbioportal)。我已经设法将 webapp-runner.jar 添加为依赖项,请参阅:https://github.com/inodb/cbioportal/tree/heroku

当我从 repo 目录运行以下命令时:

java -Djava.naming.factory.initial=org.apache.naming.java.javaURLContextFactory \
    -jar portal/target/dependency/webapp-runner.jar --port 9099 portal/target/portal

我收到这样的错误:

SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityMapper' defined in class path resource [applicationContext-business.xml]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [applicationContext-business.xml]: Cannot resolve reference to bean 'businessDataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'businessDataSource' defined in class path resource [applicationContext-business.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [java:comp/env/jdbc/mydb] is not bound in this Context. Unable to find [java:comp].

我尝试传递本地 Tomcat 安装的 context.xml 并直接在文件中设置 mysql 连接字符串,但无济于事。

【问题讨论】:

    标签: java maven tomcat heroku jndi


    【解决方案1】:

    我认为您需要将 DB URL 注册为 context.xml 文件中的 JNDI 资源,可能像这样:

    <Context>
      <Resource name="jdbc/cbioportal" auth="Container" type="javax.sql.DataSource"
                   maxTotal="100" maxIdle="30" maxWaitMillis="10000"
                   username="user" password="pass" driverClassName="com.mysql.jdbc.Driver"
                   url="jdbc:mysql://localhost:3306/dbname"/>
    </Context>
    

    然后您需要将该上下文 XML 作为选项添加到 java 命令中,如下所示:

    $ java ... \
        -jar portal/target/dependency/webapp-runner.jar \
        --context-xml context.xml --port 9099 \
        portal/target/portal
    

    对于context.xml 中的url,您必须从$ heroku config 中获取它并将其转换为jdbc url。它在运行时以$JDBC_DATABASE_URL 的形式提供,但我不确定如何动态地将其放入 context.xml。

    因此,我认为如果可能,最好不要使用 JNDI。您可以直接在您的应用程序中配置数据库参数吗?

    我从 this line in your config 获得了 JNDI 名称

    有关 JNDI 与 Tomcat 的更多信息,请参阅the Tomcat docs

    有关 webapp-runner 选项的更多信息,请参阅project readme

    【讨论】:

    • 对于任何阅读本文的人。使用 context.xml 不起作用,不使用 JNDI 解决了问题。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-25
    • 2016-09-25
    • 1970-01-01
    • 2012-06-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多