如何 运行 cbioportal tomcat war 使用 heroku 的 webapp-runner.jar

How to run cbioportal tomcat war using heroku's webapp-runner.jar

我一直在关注 Heroku 的教程 (https://devcenter.heroku.com/articles/java-webapp-runner) to learn how to run a war file using webapp-runner.jar. Now I would like to run cbioportal (https://github.com/cbioportal/cbioportal) on heroku. I've managed to add the webapp-runner.jar as a dependency, see: 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 连接字符串,但无济于事。

我认为您需要将数据库 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 名称

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

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