5

इंजेक्शन करते हैं तो मेरे पास @Stateless बीन है जो दो इंटरफेस (दूरस्थ और स्थानीय) लागू करता है। मैंने नो-इंटरफ़ेस दृश्य के साथ बीन तक पहुंचने के लिए @LocalBean एनोटेशन भी जोड़ा है।WELD-001408 असीमित निर्भरता जब EntityManager

@Stateless 
@LocalBean 
public class WeatherDataBean implements WeatherDataBeanRemote, WeatherDataBeanLocal { 
    @Inject 
    private EntityManager entityManager; 

    public WeatherDataBean() { 

    } 
    // ....attributes, getter & setter methods .... 
} 

मैं इस कारण from this example of JBoss AS7 quickstart लिया के लिए @Inject का उपयोग करें:

We use the "resource producer" pattern, from CDI, to "alias" the old fashioned @PersistenceContext injection of the entity manager to a CDI style injection. This allows us to use a consistent injection style (@Inject) throughout the application.

अब पहले से मैं का इस्तेमाल किया है:

@PersistenceContext(unitName="WeatherStationJPA") 
private EntityManager entityManager; 

EJB में है और यह किसी भी समस्या के बिना काम करता है।

WELD-001408 Unsatisfied dependencies for type [EntityManager] with qualifiers [@Default] at injection point [[field] @Inject private ejb.WeatherDataBean.entityManager]

यहाँ कैसे मैं कक्षा संसाधन को परिभाषित किया है किया गया है:: लेकिन @Inject टिप्पणी के साथ मैं इस त्रुटि मिलती है

public class Resources { 
    @SuppressWarnings("unused") 
    @PersistenceContext(unitName="WeatherStationJPA") 
    @Produces 
    private EntityManager entityManager; 

    @Produces 
    FacesContext getFacesContext() { 
     return FacesContext.getCurrentInstance(); 
    } 
} 

क्यों है कि मैं इस त्रुटि अगर मैं इकाई प्रबंधक इंजेक्षन करने की कोशिश प्राप्त है?

संपादित करें: @LightGuard मैं संकुल है कि मैं एनोटेशन संदर्भित करने के लिए उपयोग कर रहा हूँ द्वारा जोड़ा जा रहा से अनुरोध पर:

  1. WeatherDataBean है:

    import javax.ejb.LocalBean; 
    import javax.ejb.Stateless; 
    import javax.inject.Inject; 
    
  2. संसाधन है :

    import javax.enterprise.inject.Produces; 
    import javax.faces.context.FacesContext; 
    import javax.inject.Singleton; 
    import javax.persistence.EntityManager; 
    import javax.persistence.PersistenceContext; 
    
+0

सबकुछ सही दिखता है। क्या आप वाकई सही एनोटेशन (पैकेज जांचें) हैं? यह भी निर्भर करता है कि आप चीजें पैकेजिंग कैसे कर रहे हैं। – LightGuard

+0

कृपया मेरा उत्तर जांचें मैंने इन एनोटेशन के लिए उपयोग किए जाने वाले पैकेजों को जोड़ा है। मैं ईजेबी प्रोजेक्ट, ईजेबीसीएलएन्ट प्रोजेक्ट, जेपीए प्रोजेक्ट और जेएसएफ प्रोजेक्ट को पैकेज करने के लिए ईएआर प्रोजेक्ट का उपयोग कर रहा हूं। –

+0

आह, ठीक है अगर आप एक ईएआर चीजों का उपयोग कर रहे हैं तो थोड़ा सा बदलाव करें। आपको यह पता लगाना होगा कि आप इंजेक्शन कहां कर रहे हैं, कक्षाएं कौन सी लाइब्रेरी हैं और आपकी बीन्स.एक्सएमएल फाइलें कहां स्थित हैं। – LightGuard

उत्तर

5

मैं सिर्फ एक ही समस्या थी, मैं अपने प्रोजेक्ट

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; 
import javax.persistence.EntityManager; 
import javax.persistence.PersistenceContext; 

/** 
* 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(); 
    } 

} 
6

मैं एक ऐसी ही त्रुटि का सामना किया है, इस वर्ग जोड़कर इस तय, निकला मैं एक सेम डाल नहीं किया। वेब-आईएनएफ फ़ोल्डर में एक्सएमएल फ़ाइल। Beans.xml फ़ाइल WEB-INF फ़ोल्डर में बैठी एक खाली फ़ाइल हो सकती है। जेबीओएसएएस उस फाइल को सीडीआई सेवा शुरू करने के लिए जांचता है।