简体   繁体   English

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

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

I've been following the tutorial from Heroku ( https://devcenter.heroku.com/articles/java-webapp-runner ) to learn how to run a war file using webapp-runner.jar. 我一直在关注Heroku的教程( https://devcenter.heroku.com/articles/java-webapp-runner ),以了解如何使用webapp-runner.jar运行war文件。 Now I would like to run cbioportal ( https://github.com/cbioportal/cbioportal ) on heroku. 现在我想在heroku上运行cbioportal( https://github.com/cbioportal/cbioportal )。 I've managed to add the webapp-runner.jar as a dependency, see: https://github.com/inodb/cbioportal/tree/heroku . 我已设法将webapp-runner.jar添加为依赖项,请参阅: https//github.com/inodb/cbioportal/tree/heroku

When I run the following from the repo directory: 当我从repo目录运行以下命令时:

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

I get an error like this: 我收到这样的错误:

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].

I've tried passing the context.xml of my local Tomcat install and setting the mysql connection string directly in the file but to no avail. 我已经尝试传递我的本地Tomcat安装的context.xml并直接在文件中设置mysql连接字符串,但无济于事。

I think you'll need to register the DB URL as a JNDI resource in a context.xml file, maybe like this: 我想你需要在context.xml文件中将DB URL注册为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>

Then you'd need to add that context XML as an option to the java command like this: 然后你需要将这个上下文XML作为一个选项添加到java命令中,如下所示:

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

For the url in the context.xml , you'll have to get that from your $ heroku config and convert it into a jdbc url. 对于context.xmlurl ,您必须从$ heroku config获取它并将其转换为jdbc url。 It is available at runtime as $JDBC_DATABASE_URL , but I'm not sure how to get that into the context.xml dynamically. 它在运行时以$JDBC_DATABASE_URL ,但我不确定如何动态地将它导入context.xml。

For that reason, I think you're better off not using JNDI if possible. 出于这个原因,我认为如果可能的话,最好不要使用JNDI。 Can you configure the DB params directly in your app? 你可以直接在你的应用程序中配置DB参数吗?

I got the JNDI name from this line in your config 在你的配置中从这一行获得了JNDI名称

For more on JNDI with Tomcat see the Tomcat docs . 有关Tomcat的JNDI的更多信息,请参阅Tomcat文档

For more on webapp-runner options see the project readme . 有关webapp-runner选项的更多信息,请参阅项目自述文件

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

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