简体   繁体   中英

webapp-runner error (NoInitialContextException)

I have a webapp project (in J2EE) that uses Spring and maven. Usually I run this project in my Eclipse tomcat (for debugging purposes). Now I wanna run this in Heroku and I follow the tutorial in https://devcenter.heroku.com/articles/java-webapp-runner

But when I run the command java -jar target/dependency/webapp-runner.jar target/*.war the following error is giving me:

javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]

I have in my project the following files in webapp/WEB-INF: application-context.xml, servlet.xml and web.xml. The jndi configuration in application-context is:

<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/standard"/>

How can I fix this error

I had the same issue with a spring 3 / tomcat configuration, making it run on heroku, and I just resolved it, I had this in my application-context.xml

  <bean id="dataSource"
      class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName">
        <value>java:comp/env/jdbc/catWDB</value>
    </property>
</bean>

And a file on src/main/webapp/META-INF/context.xml which had the URL, user, password and other variables.

I replaced the bean dataSource in application-context.xml with

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://SERVER:3306/DATA_BASE?zeroDateTimeBehavior=convertToNull&amp;autoReconnect=true"/>
    <property name="username" value="USERNAME"/>
    <property name="password" value="PASSWORD"/>
</bean>

I now I can deploy using heroku's web-app-runner adding this command

web: java -jar target/dependency/webapp-runner.jar target/*.war --port $PORT

to the Procfile

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.

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