通过IntelliJ IDEA 13部署的Tomcat war返回错误 [英] Tomcat war deployed via IntelliJ IDEA 13 is returning error

查看:173
本文介绍了通过IntelliJ IDEA 13部署的Tomcat war返回错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在IntelliJ中部署第一个WAR文件时出现以下错误。据说这是一个本地问题,因为这只是我们为测试我们的设置而部署的一个WAR文件。

I'm getting the following error deploying my first WAR file in IntelliJ. It is a local issue, supposedly, as this is just a WAR file we deploy to test our setup.

所有80个Maven测试都在通过,但当我浏览到网络应用程序,我收到此错误:

All 80 Maven tests are passing, but when I browse to the web app, I get this error:

java.lang.IllegalArgumentException: javax.naming.NameNotFoundException: Name [jdbc/ipam] is not bound in this Context. Unable to find [jdbc].
    com.myapp1.ipam.rest.JaxRsApplication.<init>(JaxRsApplication.java:26)
    sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    org.glassfish.hk2.utilities.reflection.ReflectionHelper.makeMe(ReflectionHelper.java:1104)
    org.jvnet.hk2.internal.Utilities.justCreate(Utilities.java:902)
    org.jvnet.hk2.internal.ServiceLocatorImpl.create(ServiceLocatorImpl.java:872)
    org.jvnet.hk2.internal.ServiceLocatorImpl.createAndInitialize(ServiceLocatorImpl.java:964)
    org.jvnet.hk2.internal.ServiceLocatorImpl.createAndInitialize(ServiceLocatorImpl.java:956)
    org.glassfish.jersey.server.ApplicationHandler.createApplication(ApplicationHandler.java:336)
    org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:315)
    org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:285)
    org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:310)
    org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:170)
    org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:358)
    javax.servlet.GenericServlet.init(GenericServlet.java:158)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    java.lang.Thread.run(Thread.java:745)

这似乎是问题所在:

    public JaxRsApplication() {
    DataSource datasource;
    try {
        Context initCtx = new InitialContext();
        Context envCtx = (Context) initCtx.lookup("java:comp/env");
        datasource = (DataSource) envCtx.lookup("jdbc/ipam");
    } catch (NamingException e) {
        throw new IllegalArgumentException(e);
    }
    this.init(new SystemConfiguration(datasource));
}

这是我第一次使用IntelliJ,而且我是Java新手,所以我不知道该怎么做。

This is my first time using IntelliJ, and I am new to Java, so I'm not sure what to do here.

这是 context-fragment.xml

<?xml version='1.0' encoding='utf-8'?>
<Context>
    <Resource name="jdbc/ipam"
              factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
              auth="Container"
              type="javax.sql.DataSource"
              initialSize="2"
              maxActive="5"
              maxIdle="5"
              minIdle="1"
              maxWait="10000"
              removeAbandoned="true"
              removeAbandonedTimeout="60"
              logAbandoned="true"
              defaultReadOnly="false"
              username="**********"
              password="**********"
              driverClassName="org.postgresql.Driver"
              validationQuery="select 1"
              validationQueryTimeout="5"
              logValidationErrors="true"
              testOnBorrow="true"
              testWhileIdle="true"
              url="jdbc:postgresql://db1host/ipam_dev_table_here"/>
</Context>


推荐答案

确保已设置IntelliJ以部署上下文.xml文件启动tomcat时。您可以通过以下方式执行此操作

Make sure that you have setup IntelliJ to deploy the context.xml file when it starts tomcat. You can do this by


  1. 从文件菜单中选择项目结构

  1. Select "Project Structure" from the File menu

从那里,选择Facets选项。确保已配置Web构面。如果没有,请添加一个。

From there, select the "Facets" option. Make sure that you have a Web facet configured. If not, add one.

添加Web构面后,选择添加Application Server特定描述符...

Once the web facet is added, select "Add Application Server specific descriptor..."

从选项中选择Tomcat Context Descriptor,然后单击OK。

Select Tomcat Context Descriptor from the options and click OK.

默认情况下,IntelliJ将指向META- INF / context.xml的。如果这不是上下文文件的位置,则需要编辑文件的路径。

By default IntelliJ will point to META-INF/context.xml. If this is not the location of your context file, you will need to edit the Path to the file.

这篇关于通过IntelliJ IDEA 13部署的Tomcat war返回错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆