sping Ibatis 出现Invalid property 'sqlMapClient' of bean class [com.yh.dao.UserDao

小牛毛 2014-03-01 05:03:16
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao' defined in ServletContext resource [/WEB-INF/config/user/spring-user.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'sqlMapClient' of bean class [com.yh.dao.UserDao]: Bean property 'sqlMapClient' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1279)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269)
... 46 more
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'sqlMapClient' of bean class [com.yh.dao.UserDao]: Bean property 'sqlMapClient' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:801)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:651)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:78)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:59)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1276)
... 57 more


代码:
WEB-INF/config/applicationContext.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-2.0.xsd">

<!-- SqlMapClient -->
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<!-- 指定配置文件的位置,让spring去寻找 -->
<property name="configLocation">
<value>/WEB-INF/config/SqlMapConfig.xml</value>
</property>
</bean>
<!-- 配置数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/test-vtm?useUnicode=true&characterEncoding=UTF-8</value>
<!-- ?useUnicode=true&characterEncoding=UTF-8 -->

</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>123456</value>
</property>
</bean>

</beans>


WEB-INF\config\SqlMapConfig.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-config-2.dtd">

<sqlMapConfig>
<sqlMap resource="com/yh/model/User.xml" />
</sqlMapConfig>


WEB-INF\config\user\spring-user.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-2.5.xsd">
<!--http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 配置不能太高,太高會從網上下載 -->

<bean id="userAction" class="com.yh.web.UserAction">
<property name="userService">
<ref bean="userService" />
</property>

</bean>

<bean id="userService" class="com.yh.service.UserService">
<property name="userDao">
<ref bean="userDao" />
</property>
</bean>

<bean id="userDao" class="com.yh.dao.UserDao">
<!-- 将工厂注入到用户dao层 -->
<property name="sqlMapClient">
<ref bean="sqlMapClient" />
</property>
</bean>

</beans>


User.xml

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE sqlMap
PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-2.dtd">
<sqlMap namespace="User">
<!-- 设置别名 -->
<typeAlias alias="user" type="com.yh.model.User" />




<select id="findUserListCount" resultClass="int">
select count(*) from user
</select>


<!--insert id="insertUser" parameterClass="user">
INSERT INTO
user(NAME,PWD)
VALUES (#name#, #pwd#)

</insert-->

</sqlMap>


spring 是可以的,在没配置ibatis的时候!这问题困扰了一天了,求大神指导!!
...全文
974 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
7047bf472f32a076 2014-07-10
  • 打赏
  • 举报
回复
帮你顶下 别沉了。我也遇到这个问题呢。。 @Resource(name = "sqlMapClient") private SqlMapClient sqlMapClient; @PostConstruct public void initSqlMapClient(){ super.setSqlMapClient(sqlMapClient); } 这样就报类型错误。。。。。。。。
小牛毛 2014-03-01
  • 打赏
  • 举报
回复
小牛毛 2014-03-01
  • 打赏
  • 举报
回复
求回复哦!真的搞的累了
小牛毛 2014-03-01
  • 打赏
  • 举报
回复
实在是找不出问题在哪

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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