SSH——No bean named 'AssistantService' is defined。。
丁丁枳枳 2015-03-20 05:13:28 报错:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'LoginAction' defined in ServletContext resource [/WEB-INF/classes/applicationContext.xml]: Cannot resolve reference to bean 'AssistantService' while setting bean property 'AssistantService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'AssistantService' is defined
代码如下:
applicationContext.xml:
<bean id="AssistantDao" class="dao.impl.AssistantDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="AssistantService" class="service.AssistantServiceImpl">
<property name="AssistantDao">
<ref bean="AssistantDao" />
</property>
</bean>
<bean id="LoginAction" class="action.LoginAction">
<property name="AssistantService">
<ref bean="AssistantService" />
</property>
</bean>
AssistantDaoImpl.java:
public class AssistantDaoImpl implements AssistantDao {
@Resource
private SessionFactory sessionFactory;
private static AssistantDaoImpl assistantDaoImpl = new AssistantDaoImpl();
public static AssistantDaoImpl getInstance() {
// TODO Auto-generated method stub
return assistantDaoImpl;
}
public void setSessionFactory(SessionFactory sessionFactory){
this.sessionFactory=sessionFactory;
}
public SessionFactory getSessionFactory(){
return sessionFactory;
}
}
AssistantServiceImpl.java:
@Service
public class AssistantServiceImpl implements AssistantService{
private AssistantDao assistantDao;
public AssistantDao getAssistantDao() {
return assistantDao;
}
public void setAssistantDao(AssistantDao assistantDao) {
this.assistantDao = assistantDao;
}
}
LoginAction.java:
@Repository
public class LoginAction extends BaseAction {
private static final long serialVersionUID = 1L;
@Autowired
private StudentService studentService; // 使用Spring注解注入业务方法
@Autowired
private TeacherService teacherService; // 使用Spring注解注入业务方法
@Autowired
private PersonInChargeService personinchargeService; // 使用Spring注解注入业务方法
private AssistantService assistantService; // 使用Spring注解注入业务方法
public AssistantService getAssistantService() {
return assistantService;
}
public void setAssistantService(AssistantService assistantService) {
this.assistantService = assistantService;
}
}