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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在做SSH2框架时出现的错误:相关的知识,希望对你有一定的参考价值。

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>

部分代码如下:
Login.java

public class Login implements Ilogin
private IuserDao iUserDao;

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

把getset再重新生成一遍
下面的依赖注入都重新改下
参考技术A [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方法注入
参考技术B 建议将Login.java中的setIuserDao方法重新生成一下,你是自己手写的吗?根据spring的注入机制正确的方法名应该是setIUserDao()其中I和U都是要大写的...............希望你能明白.......

以上是关于在做SSH2框架时出现的错误:的主要内容,如果未能解决你的问题,请参考以下文章

golang的beego框架开发时出现的问题纪录

使用Maven加载项目有Dubbo框架时出现的常见异常情况

关于JDBC连接数据库时出现的Public Key Retrieval is not allowed错误

一个在写银行系统作业时出现的逻辑错误

SSH2框架(理论篇)--SSH2 Vs 经典三层

[转]ssh2三大框架整合