那位高手帮我看下这个问题Cannot convert value of type [] to required type [] for property 'ba

幻想多巴胺 2012-04-17 12:23:28
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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<!-- 开启注解处理器 -->

<!-- 定义使用C3P0连接池的数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="jdbcUrl">
<value>jdbc:mysql://localhost:3306/mysys?useUnicode=true&characterEncoding=gbk</value>
</property>
<property name="user">
<value>root</value>
</property>
<property name="password">
<value>root</value>
</property>
<!-- 设置数据库连接池的最大连接数 -->
<property name="maxPoolSize">
<value>20</value>
</property>
<!-- 设置数据库连接池的最小连接数 -->
<property name="minPoolSize">
<value>2</value>
</property>
<!-- 设置数据库连接池的初始化连接数 -->
<property name="initialPoolSize">
<value>2</value>
</property>
<!-- 设置数据库连接池的连接的最大空闲时间,单位为秒 -->
<property name="maxIdleTime">
<value>20</value>
</property>
</bean>
<!-- 读取ibatis配置文件org.springframework.orm.ibatis.SqlMapClientFactoryBean -->
<bean id="sqlMapClient" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource" />
</property>
<property name="configLocation" value="classpath:configibatis/SqlMapConfig.xml"></property>
</bean>

<!-- 把加载了 配置文件的 sqlMapClient 注入 SqlSessionTemplate模板-->
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlMapClient" />
</bean>

<!-- 通过spring 把已经加载ibatis配置文件sqlMapClient bean 注入到 dao类 供 dao类查询数据 -->
<bean id="basedao" class="com.sysbase.dao.baseDaoImpl">
<!-- 使用构造器注入 -->
<constructor-arg ref="sqlSession" />
</bean>

<!-- 部署系统用户管理业务逻辑组件AdminServiceImpl -->
<bean id="adminService" class="com.sysbase.service.impl.adminServiceImpl" >
<property name="basedao" ref="basedao"/>
</bean>

<bean id="adminAction" class="com.sysbase.struts.action.adminAction" scope="prototype">
<property name="service" ref="adminService"/>
</bean>

</beans>

service配置

package com.sysbase.service.impl;

import java.util.List;

import com.sysbase.dao.baseDao;
import com.sysbase.service.adminService;

public class adminServiceImpl implements adminService
{
private baseDao basedao;

public List browseAdmin()
{
return basedao.queryAll("Admin.queryAll");
}

public baseDao getBasedao() {
return basedao;
}

public void setBasedao(baseDao basedao) {
this.basedao = basedao;
}




}

dao类
package com.sysbase.dao;

import java.util.List;
import org.apache.ibatis.session.SqlSession;

public class baseDaoImpl {
private SqlSession sqlSession ;

public baseDaoImpl(SqlSession sqlSession )
{
this.sqlSession = sqlSession;
}

public List<Object> queryAll(String queryName)
{
return sqlSession.selectList(queryName);
}
}


报错:

Error creating bean with name 'adminService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.sysbase.dao.baseDaoImpl' to required type 'com.sysbase.dao.baseDao' for property 'basedao'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.sysbase.dao.baseDaoImpl] to required type [com.sysbase.dao.baseDao] for property 'basedao': no matching editors or conversion strategy found




全部错误:
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'adminService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.sysbase.dao.baseDaoImpl' to required type 'com.sysbase.dao.baseDao' for property 'basedao'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.sysbase.dao.baseDaoImpl] to required type [com.sysbase.dao.baseDao] for property 'basedao': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4172)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4671)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1041)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:964)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:502)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1061)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:701)
at org.apache.catalina.startup.Catalina.start(Catalina.java:585)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.sysbase.dao.baseDaoImpl' to required type 'com.sysbase.dao.baseDao' for property 'basedao'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.sysbase.dao.baseDaoImpl] to required type [com.sysbase.dao.baseDao] for property 'basedao': no matching editors or conversion strategy found
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:462)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:499)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:493)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1371)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1330)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
... 35 more
Caused by: java.lang.IllegalStateException: Cannot convert value of type [com.sysbase.dao.baseDaoImpl] to required type [com.sysbase.dao.baseDao] for property 'basedao': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:231)
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:447)
... 41 more
2012-4-17 0:01:05 org.apache.catalina.core.StandardContext start
严重: Error listenerStart

这个怎么解决,谢谢
...全文
5875 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
多谢大神们,我的问题解决了,就是忘了写实现借口了,晕死!
幻想多巴胺 2012-04-17
  • 打赏
  • 举报
回复
谢谢各位了,是这个原因 baseDaoImpl 这个类有没有实现baseDao接口。
rogerwang0618 2012-04-17
  • 打赏
  • 举报
回复
Failed to convert property value of type 'com.sysbase.dao.baseDaoImpl' to required type 'com.sysbase.dao.baseDao' for property 'basedao'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.sysbase.dao.baseDaoImpl] to required type [com.sysbase.dao.baseDao] for property 'basedao':
意思是说com.sysbase.dao.baseDaoImpl不能赋值给com.sysbase.dao.baseDao,应该baseDaoImpl实现接口baseDao,这样才可以赋值。
cxw3152 2012-04-17
  • 打赏
  • 举报
回复
把除了basedao以外的注入全部注释掉 看是否还有错误 如果没有的话按下面的方式配置一下 。。看看可以不
<bean id="adminService" class="com.sysbase.service.impl.adminServiceImpl" parent="baseDao" >
<property name="basedao" ref="basedao"/>
</bean>

cxw3152 2012-04-17
  • 打赏
  • 举报
回复
baseDaoImpl 这个类有没有实现baseDao接口。
tommore 2012-04-17
  • 打赏
  • 举报
回复
public class baseDaoImpl 声明是不是错了应该是:
public class baseDaoImpl implements baseDao
也就是没有实现接口,所以注入失败。

81,092

社区成员

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

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