मुझे पता है कि इसके बारे में बहुत सारे प्रश्न हैं। मैंने उनमें से बहुत से देखा लेकिन समस्या अभी भी बनी हुई है।स्प्रिंग बीन्स बनाया गया लेकिन स्वायत्त नहीं
मेरे पास एक सेवा है जो बनाई गई है लेकिन स्वतः नहीं है। कोई (!) मैन्युअल दीक्षा नहीं है, न तो परियोजना में और न ही परीक्षणों में (जैसे this question)
दोनों बीन्स पाए जाते हैं और बनाए जाते हैं, टॉमकैट आउटपुट कहते हैं। कम से कम पहली सेवा इंजेक्शन नहीं है जहां यह होना चाहिए। मैं दूसरे के बारे में नहीं जानता।
सेवा (इंटरफेस):
public interface SchoolService {
public School getSchool(String id);
}
सेवा (कार्यान्वयन):
@Service
@Transactional
public class SchoolServiceImpl implements SchoolService {
@Autowired
private SchoolDAO schoolDAO;
public School getSchool(String id) {
//database things
return school;
}
}
हो जाता है जहां यह "कहा जाता है"
public class SchoolMenu implements Serializable {
@Autowired
private SchoolService schoolService;
public SchoolMenu() {
//here schoolService is null
School school = schoolService.getSchool("id");
}
}
आवेदन-context.xml
<?xml version='1.0' encoding='UTF-8' ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
<bean id="SchoolServiceImpl" class="content_management.School.service.SchoolServiceImpl"/>
<bean id="SchoolDAOImpl" class="content_management.School.dao.SchoolDAOImpl"/>
</beans>
बिलाव आउटपुट:
org.springframework.beans.factory.support.DefaultListableBeanFactory: Pre-instantiating singletons in org.s[email protected]57003970: defining beans [SchoolServiceImpl,SchoolDAOImpl]; root of factory hierarchy
org.springframework.beans.factory.support.DefaultListableBeanFactory: Creating shared instance of singleton bean 'SchoolServiceImpl'
org.springframework.beans.factory.support.DefaultListableBeanFactory: Creating instance of bean 'SchoolServiceImpl'
org.springframework.beans.factory.support.DefaultListableBeanFactory: Eagerly caching bean 'SchoolServiceImpl' to allow for resolving potential circular references
org.springframework.beans.factory.support.DefaultListableBeanFactory: Finished creating instance of bean 'SchoolServiceImpl'
org.springframework.beans.factory.support.DefaultListableBeanFactory: Creating shared instance of singleton bean 'SchoolDAOImpl'
org.springframework.beans.factory.support.DefaultListableBeanFactory: Creating instance of bean 'SchoolDAOImpl'
org.springframework.beans.factory.support.DefaultListableBeanFactory: Eagerly caching bean 'SchoolDAOImpl' to allow for resolving potential circular references
org.springframework.beans.factory.support.DefaultListableBeanFactory: Finished creating instance of bean 'SchoolDAOImpl'
मेरे त्रुटि है?
आप निर्माता से क्षेत्र का उपयोग करने से पहले स्प्रिंग कुछ भी करने को का अवसर मिल सके प्रयास कर रहे हैं। – chrylis