मेरा ऐप-config.xml मेरी UserDao सेम के लिए एक परिभाषा है है:क्षेत्र autowire नहीं किया जा सका, लेकिन मैं परिभाषा
<bean id="userDao" class="com.blah.core.db.hibernate.UserDaoImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
मैं अपने घटक स्कैनिंग है:
<context:component-scan base-package="com.blah" />
मेरे सूचकांक कार्रवाई मेरे होमकंट्रोलर में ठीक काम करता है (यह मेरे उपयोगकर्ता सेवा पर एक freemarker टेम्पलेट पर एक विधि की सामग्री outputs)।
@Controller
public class HomeController {
@Autowired
private UserService userService;
@RequestMapping("/")
public ModelAndView Index() {
ModelAndView mav = new ModelAndView();
mav.setViewName("index");
mav.addObject("message", userService.sayHello());
mav.addObject("username", userService.getTestUser());
return mav;
}
'getTestUser()', एक नई पद्धति है कि UserDao लिए संदर्भ बनाता है यह दिखाई देता है:
@Service
public class UserServiceImpl implements UserService{
@Autowired
UserDao userDao;
public String sayHello() {
return "hello from user service impl part 2";
}
public String getTestUser() {
return userDao.getById(1L).getUsername();
}
}
मैं त्रुटि हो रही है:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.blah.core.db.hibernate.UserDao com.blah.core.services.UserServiceImpl.userDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.blah.core.db.hibernate.UserDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
- क्या क्या मुद्दा हो सकता है?
- अगर मैंने ऑटोवायर नहीं किया है, तो मैं उपयोगकर्ताडाओ परिभाषा पर @AutoWire जोड़ने के बजाय क्या करूँगा।
ठीक है मैं उपयोगकर्ताडाओ आह लागू नहीं कर रहा था! धन्यवाद! बीटीडब्ल्यू, आप वसंत के बूटस्ट्रैप लॉग या डिबगिंग के माध्यम से मेमोरी कैसे पढ़ते हैं?) वे अच्छे कौशल हैं जिन्हें मुझे सीखना चाहिए! – Blankman
मैंने लॉगिंग और डिबगिंग के संदर्भों के साथ उत्तर अद्यतन किया है। :) – yclian