java-如何使用heroku的webapp-runner.jar运行cbioportal雄猫战争

我一直在关注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连接字符串,但无济于事.

解决方法:

我认为您需要在context.xml文件中将数据库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>

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

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

对于context.xml中的URL,您必须从$heroku配置中获取该URL,并将其转换为jdbc URL.它可以在运行时以$JDBC_DATABASE_URL的形式使用,但是我不确定如何动态地将其添加到context.xml中.

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

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

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

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

上一篇:Oracle JNDI Tomcat和Spring


下一篇:java – 正确使用JDBC连接池(Glassfish)