Java EE异常:名称java:comp未绑定在此Context中

Eug*_*gun 6 java tomcat netbeans jndi

我在Netbeans 7.2.1中有Java EE应用程序.尝试部署它(构建结束OK),我在Tomcat日志中收到错误:

Caused by: javax.naming.NameNotFoundException: Name java:comp is not bound in this Context
    at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154)
    at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
    at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
    at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
    at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)
    at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)
    at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:201)
    at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:187)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1454)
Run Code Online (Sandbox Code Playgroud)

寻找导致此错误的代码我发现如下:

public Object lookup(String name) throws NamingException {
    return getURLOrDefaultInitCtx(name).lookup(name);
    }
Run Code Online (Sandbox Code Playgroud)

这是怎么造成的,我该如何解决?

Bal*_*usC 9

这将在Tomcat中的情况下,当你有某种原因丢弃任意特定servletcontainer-JAR文件,如发生jsp-api.jar,servlet-api.jar,catalina.jar在Web应用程序的,等等/WEB-INF/lib.您应该从那里删除所有特定于servletcontainer的JAR,它们不属于那里.另外,请确保这些JAR不嵌套在您内部的其他JAR中WEB-INF/lib.

这是一个常见的启动程序错误,以便"修复"应该以不同方式解决的JSP/Servlet库上的编译错误; 即将IDE项目配置为与Netbeans中的"目标服务器"或Eclipse中的"目标运行时"相关联.然后,IDE将在编译期间自动包含服务器的库.

  • 将容器提供的库标记为pom.xml中的`provided`. (2认同)