<tfoot id='PtAT5'></tfoot>
    <bdo id='PtAT5'></bdo><ul id='PtAT5'></ul>
  • <legend id='PtAT5'><style id='PtAT5'><dir id='PtAT5'><q id='PtAT5'></q></dir></style></legend>

  • <small id='PtAT5'></small><noframes id='PtAT5'>

      1. <i id='PtAT5'><tr id='PtAT5'><dt id='PtAT5'><q id='PtAT5'><span id='PtAT5'><b id='PtAT5'><form id='PtAT5'><ins id='PtAT5'></ins><ul id='PtAT5'></ul><sub id='PtAT5'></sub></form><legend id='PtAT5'></legend><bdo id='PtAT5'><pre id='PtAT5'><center id='PtAT5'></center></pre></bdo></b><th id='PtAT5'></th></span></q></dt></tr></i><div id='PtAT5'><tfoot id='PtAT5'></tfoot><dl id='PtAT5'><fieldset id='PtAT5'></fieldset></dl></div>

        EJB 3.1 依赖注入失败

        EJB 3.1 Dependency Injection Failed(EJB 3.1 依赖注入失败)

        <small id='xgauf'></small><noframes id='xgauf'>

              <tfoot id='xgauf'></tfoot>

                <legend id='xgauf'><style id='xgauf'><dir id='xgauf'><q id='xgauf'></q></dir></style></legend>

                  <tbody id='xgauf'></tbody>
                <i id='xgauf'><tr id='xgauf'><dt id='xgauf'><q id='xgauf'><span id='xgauf'><b id='xgauf'><form id='xgauf'><ins id='xgauf'></ins><ul id='xgauf'></ul><sub id='xgauf'></sub></form><legend id='xgauf'></legend><bdo id='xgauf'><pre id='xgauf'><center id='xgauf'></center></pre></bdo></b><th id='xgauf'></th></span></q></dt></tr></i><div id='xgauf'><tfoot id='xgauf'></tfoot><dl id='xgauf'><fieldset id='xgauf'></fieldset></dl></div>
                • <bdo id='xgauf'></bdo><ul id='xgauf'></ul>

                • 本文介绍了EJB 3.1 依赖注入失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  i have created a stateless session bean like this :

                  @WebServlet(name = "ProductController", urlPatterns = {"/ProductController"})
                  public class ProductController extends HttpServlet {
                  
                    @EJB
                    private ProductFacadeBean productBean;
                  }
                  
                  @Stateless
                  public class ProductFacadeBean extends AbstractFacade<Product> implements ProductFacadeLocalInterface {
                    @PersistenceContext(unitName = "OnlineStorePU")
                    private EntityManager em;
                  
                    protected EntityManager getEntityManager() {
                      return em;
                    }
                  
                    public ProductFacadeBean() {
                      super(Product.class);
                    }
                  
                  }
                  
                  @Local
                  public interface ProductFacadeLocalInterface {
                  
                    void create(Product product);
                  
                    void edit(Product product);
                  
                    void remove(Product product);
                  
                    Product find(Object id);
                  
                    List<Product> findAll();
                  
                    List<Product> findRange(int[] range);
                  
                    int count();
                  
                  }
                  
                  
                  public abstract class AbstractFacade<T> {
                    private Class<T> entityClass;
                  
                    public AbstractFacade(Class<T> entityClass) {
                      this.entityClass = entityClass;
                    }
                  
                    protected abstract EntityManager getEntityManager();
                  
                    public void create(T entity) {
                      getEntityManager().persist(entity);
                    }
                  
                    public void edit(T entity) {
                      getEntityManager().merge(entity);
                    }
                  
                    public void remove(T entity) {
                      getEntityManager().remove(getEntityManager().merge(entity));
                    }
                  
                    public T find(Object id) {
                      return getEntityManager().find(entityClass, id);
                    }
                  
                    public List<T> findAll() {
                      javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
                      cq.select(cq.from(entityClass));
                      return getEntityManager().createQuery(cq).getResultList();
                    }
                  
                    public List<T> findRange(int[] range) {
                      javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
                      cq.select(cq.from(entityClass));
                      javax.persistence.Query q = getEntityManager().createQuery(cq);
                      q.setMaxResults(range[1] - range[0]);
                      q.setFirstResult(range[0]);
                      return q.getResultList();
                    }
                  
                    public int count() {
                      javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
                      javax.persistence.criteria.Root<T> rt = cq.from(entityClass);
                      cq.select(getEntityManager().getCriteriaBuilder().count(rt));
                      javax.persistence.Query q = getEntityManager().createQuery(cq);
                      return ((Long) q.getSingleResult()).intValue();
                    }
                  
                  }
                  

                  Question :

                  1. What is the error about ? How to solve it ?

                    javax.naming.NamingException: Lookup failed for 'java:comp/env/Controller.ProductController/productBean' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NamingException: Exception resolving Ejb for 'Remote ejb-ref name=Controller.ProductController/productBean,Remote 3.x interface =EJB.ProductFacadeBean,ejb-link=null,lookup=,mappedName=,jndi-name=EJB.ProductFacadeBean,refType=Session' . Actual (possibly internal) Remote JNDI name used for lookup is 'EJB.ProductFacadeBean#EJB.ProductFacadeBean' [Root exception is javax.naming.NamingException: Lookup failed for 'EJB.ProductFacadeBean#EJB.ProductFacadeBean' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: EJB.ProductFacadeBean#EJB.ProductFacadeBean not found]]]

                  The full exception is attached here :

                  HTTP Status 500 -
                  
                  type Exception report
                  
                  message
                  
                  descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
                  
                  exception
                  
                  javax.servlet.ServletException: PWC1392: Error instantiating servlet class Controller.ProductController
                  
                  root cause
                  
                  com.sun.enterprise.container.common.spi.util.InjectionException: Error creating managed object for class Controller.ProductController
                  
                  root cause
                  
                  com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Remote ejb-ref name=Controller.ProductController/productBean,Remote
                  3.x interface =EJB.ProductFacadeBean,ejb-link=null,lookup=,mappedName=,jndi-name=EJB.ProductFacadeBean,refType=Session into class Controller.ProductController
                  
                  root cause
                  
                  javax.naming.NamingException: Lookup failed for 'java:comp/env/Controller.ProductController/productBean' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NamingException: Exception resolving Ejb for 'Remote ejb-ref name=Controller.ProductController/productBean,Remote
                  3.x interface =EJB.ProductFacadeBean,ejb-link=null,lookup=,mappedName=,jndi-name=EJB.ProductFacadeBean,refType=Session' .  Actual (possibly internal) Remote JNDI name used for lookup is 'EJB.ProductFacadeBean#EJB.ProductFacadeBean' [Root exception is javax.naming.NamingException: Lookup failed for 'EJB.ProductFacadeBean#EJB.ProductFacadeBean' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: EJB.ProductFacadeBean#EJB.ProductFacadeBean not found]]]
                  
                  root cause
                  
                  javax.naming.NamingException: Exception resolving Ejb for 'Remote ejb-ref name=Controller.ProductController/productBean,Remote
                  3.x interface =EJB.ProductFacadeBean,ejb-link=null,lookup=,mappedName=,jndi-name=EJB.ProductFacadeBean,refType=Session' .  Actual (possibly internal) Remote JNDI name used for lookup is 'EJB.ProductFacadeBean#EJB.ProductFacadeBean' [Root exception is javax.naming.NamingException: Lookup failed for 'EJB.ProductFacadeBean#EJB.ProductFacadeBean' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: EJB.ProductFacadeBean#EJB.ProductFacadeBean not found]]
                  
                  root cause
                  
                  javax.naming.NamingException: Lookup failed for 'EJB.ProductFacadeBean#EJB.ProductFacadeBean' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: EJB.ProductFacadeBean#EJB.ProductFacadeBean not found]
                  
                  root cause
                  
                  javax.naming.NameNotFoundException: EJB.ProductFacadeBean#EJB.ProductFacadeBean not found
                  
                  note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 3.1 logs. GlassFish Server Open Source Edition 3.1
                  

                  1. When i created the session for entity bean using netbeans it created the abstract facade for us ? What is the purpose ? I know facade pattern is to serve as interface to route the request ?
                  2. What is the use of ejb-jar.xml ?

                  All settings are default. The ejb bean is created inside java ee 6 web application rather than in another war or jar. Glassfish 3.1 server.

                  Please help.

                  Thanks.

                  解决方案

                  you must use the interface. If you use Seam Solder and CDI you can specify the exact implementation with

                  @Inject
                  @Exact(ProductFacadeBean.class)
                  

                  这篇关于EJB 3.1 依赖注入失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Maven JAVA_HOME environment variable is not defined correctly, but it is(Maven JAVA_HOME 环境变量未正确定义,但它是)
                  Java System Environment Variable(Java 系统环境变量)
                  Java -classpath option(Java -classpath 选项)
                  Read environment variable in SpringBoot(在 SpringBoot 中读取环境变量)
                  Tomcat 8 - context.xml use Environment Variable in Datasource(Tomcat 8 - context.xml 在数据源中使用环境变量)
                  Issue with JAVA_HOME(JAVA_HOME 的问题)
                  <tfoot id='Q5LyP'></tfoot>

                    • <small id='Q5LyP'></small><noframes id='Q5LyP'>

                      1. <legend id='Q5LyP'><style id='Q5LyP'><dir id='Q5LyP'><q id='Q5LyP'></q></dir></style></legend>
                        <i id='Q5LyP'><tr id='Q5LyP'><dt id='Q5LyP'><q id='Q5LyP'><span id='Q5LyP'><b id='Q5LyP'><form id='Q5LyP'><ins id='Q5LyP'></ins><ul id='Q5LyP'></ul><sub id='Q5LyP'></sub></form><legend id='Q5LyP'></legend><bdo id='Q5LyP'><pre id='Q5LyP'><center id='Q5LyP'></center></pre></bdo></b><th id='Q5LyP'></th></span></q></dt></tr></i><div id='Q5LyP'><tfoot id='Q5LyP'></tfoot><dl id='Q5LyP'><fieldset id='Q5LyP'></fieldset></dl></div>
                        • <bdo id='Q5LyP'></bdo><ul id='Q5LyP'></ul>

                            <tbody id='Q5LyP'></tbody>