编程语言
首页 > 编程语言> > 将EJB3注入基于注释的JSF2 Backing bean导致javax.naming.NameNotFoundException:

将EJB3注入基于注释的JSF2 Backing bean导致javax.naming.NameNotFoundException:

作者:互联网

我已经看到其他thread有类似的问题,但无法解决我的问题的直接链接.希望我不是在重复一个问题.我的问题是:我使用带有JSF2的Webpsphere 7作为共享隔离库.当我尝试将EJB3注入带注释的JSF2支持bean时,我收到此错误

Caused by: javax.naming.NameNotFoundException: Name comp/env/helloworld.HelloBean not found in context "java:".

但是如果我们使用face.xml配置JSF2而不使用注释,它可以正常工作.但是,如果没有EJB3注入,我们可以使用带有JSF2注释的应用程序,并且只有在我们尝试注入ejb3时才会看到任何问题.下面是一个简单的试用应用程序的代码

服务界面:

package au.com.test;

import javax.ejb.Local;

@Local
public interface SampleService {
    public String getServiceName();
}

服务实施:

package au.com.test;

import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;


@Stateless
@TransactionAttribute (TransactionAttributeType.NOT_SUPPORTED)
public class SampleSession implements SampleService {

    @Override
    public String getServiceName() {
        return "Sample Service";
    }

}

JSF托管bean:

package helloworld;

import java.io.Serializable;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import au.com.example.service.SampleService;

@ManagedBean
@SessionScoped
public class HelloBean implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    private String name;    

    @EJB
    private SampleService sampleService;


    public String getName() {       
        return  sampleService.getServiceName()+ name;       
    }

    public void setName(String name) {
        this.name = name;
    }

}

堆栈跟踪如下

[2/08/11 7:52:20:394 EST] 00000034 HtmlImageRend W   ALT attribute is missing for : waveImg
[2/08/11 7:52:20:488 EST] 00000034 FaceletViewDe E   Error Rendering View[/hello.xhtml]
                                 javax.faces.FacesException: Could not retrieve value of component with path : {Component-Path : [Class: javax.faces.component.UIViewRoot,ViewId: /hello.xhtml][Class: javax.faces.component.html.HtmlBody,Id: j_id327415688_1383f7c7][Class: javax.faces.component.html.HtmlForm,Id: helloForm][Class: javax.faces.component.html.HtmlInputText,Id: username]}
    at org.apache.myfaces.shared_impl.renderkit.RendererUtils.getValue(RendererUtils.java:347)
    at org.apache.myfaces.shared_impl.renderkit.RendererUtils.getStringValue(RendererUtils.java:291)
    at org.apache.myfaces.shared_impl.renderkit.html.HtmlTextRendererBase.renderInputBegin(HtmlTextRendererBase.java:169)
    at org.apache.myfaces.shared_impl.renderkit.html.HtmlTextRendererBase.renderInput(HtmlTextRendererBase.java:158)
    at org.apache.myfaces.shared_impl.renderkit.html.HtmlTextRendererBase.encodeEnd(HtmlTextRendererBase.java:75)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:519)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:672)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:668)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:668)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:668)
    at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.renderView(FaceletViewDeclarationLanguage.java:1483)
    at org.apache.myfaces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:281)
    at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:85)
    at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:239)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:191)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1657)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:939)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:502)
    at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:179)
    at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:353)
    at com.ibm.ws.webcontainer.extension.DefaultExtensionProcessor.handleRequest(DefaultExtensionProcessor.java:784)
    at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3933)
    at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:276)
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:931)
    at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1583)
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:186)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:276)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
    at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
    at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
    at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1604)
Caused by: javax.faces.FacesException: javax.naming.NameNotFoundException: Name comp/env/helloworld.HelloBean not found in context "java:".
    at org.apache.myfaces.config.ManagedBeanBuilder.buildManagedBean(ManagedBeanBuilder.java:225)
    at org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.createManagedBean(ManagedBeanResolver.java:332)
    at org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.getValue(ManagedBeanResolver.java:295)
    at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:143)
    at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:142)
    at org.apache.myfaces.el.VariableResolverImpl.resolveVariable(VariableResolverImpl.java:65)
    at org.apache.myfaces.el.convert.VariableResolverToELResolver.getValue(VariableResolverToELResolver.java:116)
    at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:143)
    at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:142)
    at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:45)
    at org.apache.el.parser.AstValue.getValue(AstValue.java:91)
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:263)
    at org.apache.myfaces.view.facelets.el.TagValueExpression.getValue(TagValueExpression.java:85)
    at javax.faces.component._DeltaStateHelper.eval(_DeltaStateHelper.java:246)
    at javax.faces.component.UIOutput.getValue(UIOutput.java:71)
    at javax.faces.component.UIInput.getValue(UIInput.java:142)
    at org.apache.myfaces.shared_impl.renderkit.RendererUtils.getValue(RendererUtils.java:343)
    ... 39 more
Caused by: javax.naming.NameNotFoundException: Name comp/env/helloworld.HelloBean not found in context "java:".
    at com.ibm.ws.naming.ipbase.NameSpace.getParentCtxInternal(NameSpace.java:1837)
    at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java:1166)
    at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java:1095)
    at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:1233)
    at com.ibm.ws.naming.java.javaURLContextImpl.lookup(javaURLContextImpl.java:395)
    at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:214)
    at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:154)
    at javax.naming.InitialContext.lookup(InitialContext.java:436)
    at org.apache.myfaces.config.annotation.ResourceAnnotationLifecycleProvider.lookupFieldResource(ResourceAnnotationLifecycleProvider.java:127)
    at org.apache.myfaces.config.annotation.AllAnnotationLifecycleProvider.checkFieldAnnotation(AllAnnotationLifecycleProvider.java:83)
    at org.apache.myfaces.config.annotation.ResourceAnnotationLifecycleProvider.checkAnnotation(ResourceAnnotationLifecycleProvider.java:78)
    at org.apache.myfaces.config.annotation.ResourceAnnotationLifecycleProvider.processAnnotations(ResourceAnnotationLifecycleProvider.java:55)
    at org.apache.myfaces.config.annotation.NoInjectionAnnotationLifecycleProvider.newInstance(NoInjectionAnnotationLifecycleProvider.java:46)
    at org.apache.myfaces.config.ManagedBeanBuilder.buildManagedBean(ManagedBeanBuilder.java:155)
    ... 55 more

[2/08/11 7:52:20:503 EST] 00000034 ErrorPageWrit E   An exception occurred
                                 javax.faces.FacesException: javax.naming.NameNotFoundException: Name comp/env/helloworld.HelloBean not found in context "java:".
    at org.apache.myfaces.shared_impl.context.ExceptionHandlerImpl.wrap(ExceptionHandlerImpl.java:241)
    at org.apache.myfaces.shared_impl.context.ExceptionHandlerImpl.handle(ExceptionHandlerImpl.java:156)
    at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:258)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:191)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1657)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:939)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:502)
    at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:179)
    at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:353)
    at com.ibm.ws.webcontainer.extension.DefaultExtensionProcessor.handleRequest(DefaultExtensionProcessor.java:784)
    at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3933)
    at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:276)
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:931)
    at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1583)
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:186)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:276)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
    at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
    at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
    at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1604)
Caused by: javax.naming.NameNotFoundException: Name comp/env/helloworld.HelloBean not found in context "java:".
    at com.ibm.ws.naming.ipbase.NameSpace.getParentCtxInternal(NameSpace.java:1837)
    at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java:1166)
    at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java:1095)
    at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:1233)
    at com.ibm.ws.naming.java.javaURLContextImpl.lookup(javaURLContextImpl.java:395)
    at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:214)
    at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:154)
    at javax.naming.InitialContext.lookup(InitialContext.java:436)
    at org.apache.myfaces.config.annotation.ResourceAnnotationLifecycleProvider.lookupFieldResource(ResourceAnnotationLifecycleProvider.java:127)
    at org.apache.myfaces.config.annotation.AllAnnotationLifecycleProvider.checkFieldAnnotation(AllAnnotationLifecycleProvider.java:83)
    at org.apache.myfaces.config.annotation.ResourceAnnotationLifecycleProvider.checkAnnotation(ResourceAnnotationLifecycleProvider.java:78)
    at org.apache.myfaces.config.annotation.ResourceAnnotationLifecycleProvider.processAnnotations(ResourceAnnotationLifecycleProvider.java:55)
    at org.apache.myfaces.config.annotation.NoInjectionAnnotationLifecycleProvider.newInstance(NoInjectionAnnotationLifecycleProvider.java:46)
    at org.apache.myfaces.config.ManagedBeanBuilder.buildManagedBean(ManagedBeanBuilder.java:155)
    at org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.createManagedBean(ManagedBeanResolver.java:332)
    at org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.getValue(ManagedBeanResolver.java:295)
    at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:143)
    at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:142)
    at org.apache.myfaces.el.VariableResolverImpl.resolveVariable(VariableResolverImpl.java:65)
    at org.apache.myfaces.el.convert.VariableResolverToELResolver.getValue(VariableResolverToELResolver.java:116)
    at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:143)
    at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:142)
    at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:45)
    at org.apache.el.parser.AstValue.getValue(AstValue.java:91)
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:263)
    at org.apache.myfaces.view.facelets.el.TagValueExpression.getValue(TagValueExpression.java:85)
    at javax.faces.component._DeltaStateHelper.eval(_DeltaStateHelper.java:246)
    at javax.faces.component.UIOutput.getValue(UIOutput.java:71)
    at javax.faces.component.UIInput.getValue(UIInput.java:142)
    at org.apache.myfaces.shared_impl.renderkit.RendererUtils.getValue(RendererUtils.java:343)
    at org.apache.myfaces.shared_impl.renderkit.RendererUtils.getStringValue(RendererUtils.java:291)
    at org.apache.myfaces.shared_impl.renderkit.html.HtmlTextRendererBase.renderInputBegin(HtmlTextRendererBase.java:169)
    at org.apache.myfaces.shared_impl.renderkit.html.HtmlTextRendererBase.renderInput(HtmlTextRendererBase.java:158)
    at org.apache.myfaces.shared_impl.renderkit.html.HtmlTextRendererBase.encodeEnd(HtmlTextRendererBase.java:75)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:519)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:672)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:668)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:668)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:668)
    at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.renderView(FaceletViewDeclarationLanguage.java:1483)
    at org.apache.myfaces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:281)
    at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:85)
    at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:239)
    ... 26 more

谁能帮我这个 .

UPDATE
这些是位于EAR内部的两个独立模块,可以部署WAS7

解决方法:

不考虑共享库来定位组件定义注释(如@ManagedBean),因此找不到组件,这意味着在构建java:comp命名空间时找不到它的@EJB.你的选择是:

>在WAR中的faces-config.xml中提及JSF bean.
>将JSF bean放在WAR中.
>定义< ejb-ref>在web.xml中.
>在WAR中的虚拟“资源生成器”bean中使用注释定义ejb-ref.

对于#4,一个例子是:

@ManagedBean
@EJBs({
   @EJB(name="helloworld.HelloBean", type=SampleService.class)
   // ... etc
})
public class ResourceProducerBean { }

标签:java,ejb-3-0,java-ee,jsf-2,websphere-7
来源: https://codeday.me/bug/20191007/1864958.html