开发者社区 问答 正文

spring 对象引用报错?

使用spring注解后,引用对象就报错,

@Service("UserBiz")
public class UserBizImpl implements UserBiz{
 
 @Autowired

private UserDao userDao;
 
 public boolean login(UserBean userBean) {
  return userDao.login(userBean);
 }
}
xml中如下配置

<bean id="userBiz" class="com.szy.biz.impl.UserBizImpl">
    <property name="userDao" ref="userDao"></property>

</bean>
<!--指定登录的实现bean  -->
<bean id="userDao" class="com.szy.dao.impl.Test"></bean>
这样配置后就报org.springframework.beans.NotWritablePropertyException: Invalid property 'userDao' of bean class [com.szy.biz.impl.UserBizImpl]: Bean property 'userDao' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

如果我将<property》去掉

<bean id="userBiz" class="com.szy.biz.impl.UserBizImpl">
<bean id="userDao" class="com.szy.dao.impl.Test"></bean>
运行正常,求解?

展开
收起
a123456678 2016-03-16 10:32:39 1898 分享 版权
1 条回答
写回答
取消 提交回答
  • 其实是有加的 出错主要信息在于userBiz中的ref引用,去掉propery 引用就好了

    2019-07-17 19:03:31
    赞同 展开评论
问答分类:
问答标签:
问答地址: