在做SSH2框架时出现的错误:

Errorcreatingbeanwithname'Login'definedinServletContextresource[/WEB-INF/applicationC... Error creating bean with name 'Login' defined in ServletContext resource [/WEB-INF/applicationContext-beans.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'iUserDao' of bean class [com.service.impl.Login]: Bean property 'iUserDao' is not writable or has an invalid setter method. Did you mean 'iuserDao'?
Invalid property 'iUserDao' of bean class [com.service.impl.Login]: Bean property 'iUserDao' is not writable or has an invalid setter method. Did you mean 'iuserDao'?
部分代码如下:
Login.java

public class Login implements Ilogin {
private IuserDao iUserDao;

public IuserDao getIuserDao()
{
return iUserDao;
}
public void setIuserDao(IuserDao iUserDao)
{
this.iUserDao=iUserDao;
}
@Override
public Boolean login(User user) {
// TODO Auto-generated method stub
if(iUserDao.findByExample(user).size()>0)
{
return true;
}
else
{
return false;
}

}

}
applicationContext-beans.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="Login" class="com.service.impl.Login">
<property name="iUserDao">
<ref bean="UserDAO"/>
</property>
</bean>
<bean id="LoginAction" class="com.action.LoginAction">
<property name="ilogin">
<ref bean="Login"/>
</property>
</bean>
</beans>
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.objectFactory" value="spring"></constant>
<package name="Register" namespace="/" extends="struts-default">
<action name="Login" class="LoginAction" method="login">
<result name="success">/success.jsp</result>
<result name="fail">/fail.jsp</result>
</action>
</package>
</struts>
web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
applicationContext.xml
有省略。。。
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/pojo/User.hbm.xml</value></list>
</property></bean>
<bean id="UserDAO" class="com.dao.impl.UserDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
展开
 我来答
东方箭
2012-03-15 · TA获得超过708个赞
知道小有建树答主
回答量:238
采纳率:0%
帮助的人:217万
展开全部
部分代码如下:
Login.java

public class Login implements Ilogin {
private IuserDao iUserDao;

建议先把iUserDao这个变量改成userDao:
private IuserDao userDao;

把getset再重新生成一遍
下面的依赖注入都重新改下
resicintranet
2012-03-15 · 超过34用户采纳过TA的回答
知道答主
回答量:134
采纳率:100%
帮助的人:86万
展开全部
[com.service.impl.Login]: Bean property 'iUserDao' is not writable or has an invalid setter method. Did you mean 'iuserDao'?

com.service.impl.Login中你一定声明了iUserDao, 但是iUserDao在注入时没有找到对应的setter和getter方法注入
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
xiayutian0000
2012-03-15 · TA获得超过175个赞
知道小有建树答主
回答量:241
采纳率:0%
帮助的人:131万
展开全部
建议将Login.java中的setIuserDao方法重新生成一下,你是自己手写的吗?根据spring的注入机制正确的方法名应该是setIUserDao()其中I和U都是要大写的...............希望你能明白.......
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式