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. 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 .
When I run the following from the repo directory:
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.
I think you'll need to register the DB URL as a JNDI resource in a context.xml
file, maybe like this:
<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:
$ 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. It is available at runtime as $JDBC_DATABASE_URL
, but I'm not sure how to get that into the context.xml dynamically.
For that reason, I think you're better off not using JNDI if possible. Can you configure the DB params directly in your app?
I got the JNDI name from this line in your config
For more on JNDI with Tomcat see the Tomcat docs .
For more on webapp-runner options see the project readme .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.