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;
}
}


...全文
233 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
邹邹wl 2015-03-20
  • 打赏
  • 举报
回复
不知道楼上的在说些什么 你是体里面声明: private AssistantService assistantService; // 使用Spring注解注入业务方法 你要注入的是属性不是类名,也就是你需要注入的是 assistantService这个 而你配置文件里写的是类名:<property name="AssistantService"> 所以把配置文件<property name="AssistantService"> 这里的name改为 assistantService 这个问题肯定能解决
A-wolf 2015-03-20
  • 打赏
  • 举报
回复
引用 6 楼 wendylee1994 的回复:
搞好了,是build里的class文件保持不变造成的!手动修改build里的class文件就哦了!请问各位大牛,这是eclipse出问题了吗?
还是自己养成良好的习惯把 部署项目之前先clean一下
丁丁枳枳 2015-03-20
  • 打赏
  • 举报
回复
搞好了,是build里的class文件保持不变造成的!手动修改build里的class文件就哦了!请问各位大牛,这是eclipse出问题了吗?
丁丁枳枳 2015-03-20
  • 打赏
  • 举报
回复
引用 4 楼 huangcan_liu 的回复:
1、 <bean id="AssistantService" class="service.AssistantServiceImpl"> <property name="AssistantDao"> <ref bean="AssistantDao" /> 2、 @Autowired private TeacherService teacherService; 这两者都是对象的注入方法 只需要保留一种即可 另外 使用 第一种方式 在 类中注入的对象需要加入get set 方法
谢谢你回复了这么多~~ 我把Assistant全部换成了Student,它依然报错No bean named 'AssistantService' is defined,请问是不是与缓存有关?~~
A-wolf 2015-03-20
  • 打赏
  • 举报
回复
1、 <bean id="AssistantService" class="service.AssistantServiceImpl"> <property name="AssistantDao"> <ref bean="AssistantDao" /> 2、 @Autowired private TeacherService teacherService; 这两者都是对象的注入方法 只需要保留一种即可 另外 使用 第一种方式 在 类中注入的对象需要加入get set 方法
A-wolf 2015-03-20
  • 打赏
  • 举报
回复
你是不弄的有点混了 <bean id="AssistantService" class="service.AssistantServiceImpl"> <property name="AssistantDao"> <ref bean="AssistantDao" /> 使用 bean 注入 了对象 就要使用 注解注入 @Autowired 如果采用配置注入 你的 teacherService 属性就需要加get set 方法 如果采用下面注解注入 就把上面的配置删除 但是dao还是需要 配置 bean 注入 sessionFactory service 去掉 如果你的dao是hibernate 自动生成的有对应的配置 那么在 service 引用的dao 不需要注解 也不需要get set action 需要在你的struts 配置文件中配置 对应的 action 引用的对象是 你在spring配置的action id @Autowired private TeacherService teacherService; // 使用Spring注解注入业务方法
丁丁枳枳 2015-03-20
  • 打赏
  • 举报
回复
引用 1 楼 u011280732 的回复:
没有找到实体类
可不可以具体点?
123liuying 2015-03-20
  • 打赏
  • 举报
回复
没有找到实体类

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧