异常为:
2011-9-21 10:16:57 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userService' defined in file [E:\Tools\tomcat6.0.14\tomcat6.0.14\webapps\Sala\WEB-INF\classes\config\applicationContext_jwqService.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [com.dao.BaseDao]: Could not convert constructor argument value of type [java.lang.String] to required type [com.dao.BaseDao]: Failed to convert value of type 'java.lang.String' to required type 'com.dao.BaseDao'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.dao.BaseDao]: no matching editors or conversion strategy found
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:670)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:191)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:984)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:888)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:479)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:562)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:871)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:272)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:196)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3830)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4337)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
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:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
2011-9-21 10:16:57 org.apache.catalina.core.StandardContext start
applicationContext_jwqService.xml的配置
<bean id="userService" class="com.service.impl.ServiceImpl">
<!-- <property name="userDao" ref="userDao"></property> -->
<constructor-arg value="userDao" />
</bean>

解决方案 »

  1.   

    只用了Spring?web.xml中配置了吗
      

  2.   

    我web.xml的配置是
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <welcome-file-list>
    <welcome-file>Login.jsp</welcome-file>
    </welcome-file-list>
    <filter>
    <filter-name>struts2</filter-name>
    <filter-class>
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
    </filter-class>
    </filter>
    <context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>classpath:/properties/log4j.properties</param-value>
    </context-param>
    <!-- 加载Spring配置XML文件 -->
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
         classpath:/config/applicationContext*.xml
         </param-value>
    </context-param>
    <!-- 编码转换 -->
    <filter>
    <filter-name>encodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
    <param-name>encoding</param-name>
    <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
    <param-name>forceEncoding</param-name>
    <param-value>true</param-value>
    </init-param>
    </filter>
    <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>
    <!--
    Servlet2.3过滤器,用来把一个Hibernate Session和一次完整的请求过程对应的线程相绑定。目的是为了实现"Open
    Session in View"的模式。
    -->
    <filter>
    <filter-name>lazyLoadingFilter</filter-name>
    <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
    </filter>
    <!-- 定义LOG4J监听器 -->
    <listener>
       <listener-class>
    org.springframework.web.util.Log4jConfigListener
       </listener-class>
    </listener>
    <filter>
    <filter-name>struts-cleanup</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
    </filter>
    <filter>
    <filter-name>struts</filter-name>
    <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    <init-param>
             <param-name>config</param-name>
             <param-value>struts-default.xml,struts-plugin.xml,config/struts.xml,config/struts-jwq.xml</param-value>
            </init-param>
    </filter> <filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>
    <filter-mapping>
    <filter-name>lazyLoadingFilter</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>
    <!--
    <filter-mapping> <filter-name>struts-cleanup</filter-name>
    <url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher> </filter-mapping> <filter-mapping>
    <filter-name>struts</filter-name> <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher>
    </filter-mapping>
    --> <!-- 启动Spring -->
    <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <!-- 防止内存泄漏,监听服务器关闭或刷新缓存时对以前保存的信息进行清除 -->
    <listener>
    <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
    </listener>
    <!--
    基于LocalThread将HTTP
    request对象绑定到为该请求提供服务的线程上,使具有request和session作用域的bean能够在后面的调用链中被访问到
    -->
    <!--
    Servlet 2.4以下改为org.springframework.web.filter.RequestContextFilter
    -->
    <listener>
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>
    <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping></web-app>
      

  3.   

    类型不匹配?那个异常我也知道说的是BaseDao转String类型不匹配,可是哪儿有问题应该怎样纠正这个异常,还请指教啊
      

  4.   

    通过看你的意思是想把这个UserDao通过构造方法注入到userService 这个bean中来,
    所以你的配置应该是这样的<bean id="userService" class="com.service.impl.ServiceImpl">
    <!-- <property name="userDao" ref="userDao"></property> -->
    <constructor-arg name="userDao" ref="userDao" />
    </bean>
      

  5.   


       //配置文件有问题
     <bean id="userService" class="com.service.impl.ServiceImpl">
     <!-- <property name="userDao" ref="userDao"></property> -->
     <constructor-arg value="userDao" />
     </bean>
    <constructor-arg value="userDao" />这个引用肯定是String类型,但是你的ServceImpl需要的是DAO为什么会是这样,你使用的属性是value ,因此你需要改成
     <constructor-arg name="类中的属性" ref="引用对象"/>