-1
我正在運行代碼,其中存在依賴關係@PersistenceContext
和字段private EntityManager em
;這兩個都不能解析爲一個類型,這個錯誤的含義是什麼,我該如何解決它?
的代碼是在這裏:@PersistenceContext無法解析爲
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>
* @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();
}
}
感謝安舒,現在我越來越: 進口javax.persistence不能得到解決 的導入javax.persistence無法解析 –
請確保您的類路徑 – Anshu
中有必要的庫,現在解決我有「NotEmpty無法解析爲類型」@ NotEmpty'和「電子郵件無法解析到類型「@電子郵件」:) –