-1

我正在运行一个代码,其中有一个依赖项@PersistenceContext和一个字段private EntityManager em;两者都无法解析为一个类型,这个错误是什么意思,我该如何解决?
代码在这里:

package org.jboss.tools.examples.util;    

import java.util.logging.Logger;     
import javax.enterprise.context.RequestScoped;     
import javax.enterprise.inject.Produces;     
import javax.enterprise.inject.spi.InjectionPoint;     
import javax.faces.context.FacesContext;     

/**    
 * This class uses CDI to alias Java EE resources, such as the persistence context, to     
CDI beans    
 *     
 * <p>    
 * Example injection on a managed bean field:    
 * </p>    
 *     
 * <pre>    
 * &#064;Inject    
 * private EntityManager em;    
 * </pre>    
 */    
public class Resources {    
   // use @SuppressWarnings to tell IDE to ignore warnings about field not being         referenced directly    
   @SuppressWarnings("unused")    
   @Produces    
   @PersistenceContext    
   private EntityManager em;    

   @Produces    
   public Logger produceLog(InjectionPoint injectionPoint) {    
      return Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName());    
   }    

   @Produces    
   @RequestScoped    
   public FacesContext produceFacesContext() {    
      return FacesContext.getCurrentInstance();    
   }    
}    
4

1 回答 1

0

您缺少 PersistenceContext 注释和 EntityManager 的导入语句

import javax.persistence.PersistenceContext;
import javax.persistence.EntityManager;
于 2012-10-13T09:39:12.633 回答