当我使用netbean 6.9运行该项目时,我是使用j2ee的。我有这个问题

javax.naming.NamingException: Lookup failed for 'java:comp/env' in SerialContext  [Root exception is javax.naming.NamingException: Invocation exception: Got null ComponentInvocation ]
        at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:442)
        at javax.naming.InitialContext.lookup(InitialContext.java:392)
        at javax.naming.InitialContext.lookup(InitialContext.java:392)
        at com.askad.ap.util.ListReader.readPath(ListReader.java:34)
        at com.askad.ap.util.ListReader.<init>(ListReader.java:29)
        at com.askad.ap.facade.UserTransactionFacade.<init>(UserTransactionFacade.java:44)
        at com.askad.ap.facade.__EJB31_Generated__UserTransactionFacade__Intf____Bean__.<init>(Unknown Source)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at java.lang.Class.newInstance0(Class.java:355)
        at java.lang.Class.newInstance(Class.java:308)
        at com.sun.ejb.containers.BaseContainer.instantiateOptionalEJBLocalBusinessObjectImpl(BaseContainer.java:3801)
        at com.sun.ejb.containers.StatelessSessionContainer.initializeHome(StatelessSessionContainer.java:248)
        at com.sun.ejb.containers.ContainerFactoryImpl.createContainer(ContainerFactoryImpl.java:161)
        at org.glassfish.ejb.startup.EjbApplication.loadContainers(EjbApplication.java:207)
        at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:197)
        at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:63)
        at org.glassfish.internal.data.ModuleInfo.load(ModuleInfo.java:175)
        at org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:216)
        at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:338)
        at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:183)
        at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:272)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:305)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:320)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1176)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$900(CommandRunnerImpl.java:83)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1235)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1224)
        at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:365)
        at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:204)
        at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:166)
        at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:100)
        at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:245)
        at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
        at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
        at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
        at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
        at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
        at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
        at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
        at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
        at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
        at java.lang.Thread.run(Thread.java:662)
Caused by: javax.naming.NamingException: Invocation exception: Got null ComponentInvocation
        at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.getComponentId(GlassfishNamingManagerImpl.java:773)
        at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:655)
        at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:156)
        at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:428)
        ... 48 more

当我点击
com.askad.ap.util.ListReader.readPath(ListReader.java:34)

NetBean强调这一行
Context env = (Context) new InitialContext().lookup("java:comp/env");

有谁知道如何解决这个问题?什么原因导致这个问题? thx b4

最佳答案

从堆栈跟踪中,您好像正在使用Glassfish作为容器。在context.xml中,您应该定义一个或多个资源。假设您有一个名为jdbc / msql的文件。然后,您可以使用java:comp / env / jdbc / msql来引用它。似乎您在该可疑代码行中引用了一些空资源。 Hth。

关于java - 错误javax.naming.NamingException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5242423/

10-10 23:55