回顾了ssh1的一个小项目,自己写了一个登录和查student所有明细,配置好ssh后,第一个登录能成功启动,但写完查询所有student后,启动tomcat,出现以下错误,希望ggmm们帮我解析以下,我找了30个小时了,都没睡觉呢。快疯掉啦,哇哇哇哇哇~! 代码如下:
10:27:56,515 ERROR ContextLoaderPlugIn:229 - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name '/item' defined in ServletContext resource [/WEB-INF/classes/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyAccessExceptionsException: PropertyAccessExceptionsException (1 errors); nested propertyAccessExceptions are: [org.springframework.beans.TypeMismatchException: Failed to convert property value of type [com.wm.spring.service.StudentService] to required type [com.wm.spring.service.IStudentService] for property 'studentService']
PropertyAccessExceptionsException (1 errors)
org.springframework.beans.TypeMismatchException: Failed to convert property value of type [com.wm.spring.service.StudentService] to required type [com.wm.spring.service.IStudentService] for property 'studentService'
at org.springframework.beans.BeanWrapperImpl.doTypeConversionIfNecessary(BeanWrapperImpl.java:839)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:584)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:469)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:626)
at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:653)
at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:642)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1023)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:824)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:345)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:226)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:275)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:320)
at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:134)
at org.springframework.web.struts.ContextLoaderPlugIn.createWebApplicationContext(ContextLoaderPlugIn.java:353)
at org.springframework.web.struts.ContextLoaderPlugIn.initWebApplicationContext(ContextLoaderPlugIn.java:296)
at org.springframework.web.struts.ContextLoaderPlugIn.init(ContextLoaderPlugIn.java:225)
at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:1158)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:473)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4187)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4496)
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: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:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
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:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
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)
2010-5-15 10:27:56 org.apache.catalina.core.ApplicationContext log
严重: action: null

==============================================================================================================
applicationContext.xml 如下:<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"><beans>    
    <!--==================== 数据源======================= -->
    <bean id="myDataSource"
        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</value>
        </property>
        <property name="username">
            <value>root</value>
        </property>
        <property name="password">
            <value>root</value>
        </property>
    </bean>    <!--==================== 连接工厂======================= -->
    <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource">
            <ref bean="myDataSource" />
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
            </props>
        </property>
        
        <property name="mappingResources">
            <list>
                <value>com/wm/hibernate/vo/User.hbm.xml</value>
                <value>com/wm/hibernate/vo/Student.hbm.xml</value>
            </list>
        </property>
    </bean>
  
   
     <!--==================== DAO======================= -->
    <bean id="myUserLoginDao" class="com.wm.spring.dao.UserLoginDao">
        <property name="sessionFactory">
            <ref bean="mySessionFactory"/>
        </property>
    </bean>
    
    <bean id="myStudentDao" class="com.wm.spring.dao.StudentDao">
        <property name="sessionFactory">
            <ref bean="mySessionFactory"/>
        </property>
    </bean>
    
    <!--====================Service==============================--> <bean id="myUserLoginService" class="com.wm.spring.service.UserLoginService">
         <property name="userLoginDao"><ref bean="myUserLoginDao"/></property>
    </bean>    
    <bean id="myStudentService"  class="com.wm.spring.service.StudentService">
         <property name="studentDao"><ref bean="myStudentDao"/></property>
    </bean>
    
    
    
    <!--====================Action======================= -->    
    <!-- 此时要用bean的name属性,不要用id属性 -->
    
   
    <bean name="/login" class="com.wm.struts.action.LoginAction">
        <property name="userLoginService">
            <ref bean="myUserLoginService"/>
        </property>
    </bean>     <bean name="/item"  class="com.wm.struts.action.ItemAction" >
        <property name="studentService">
            <ref bean="myStudentService"/>
        </property>
    </bean>
    
   
</beans>
求求哥哥姐姐们帮帮小弟弟我呀~

解决方案 »

  1.   

    另外:小弟我在applicationContext.xml中的那些配置,用myEclipse里 ctrl+鼠标都能点出来那些链接,到底是哪出错啦呀~!?
      

  2.   

    相应的set方法啦~都有的啦~!
      

  3.   

    错误都说得很清楚了!..[这些英文不难看懂0]错误原因:
    注入studentServiceImpl时出的错TypeMismatchException类型不对!在Action中你用的是了IStudentService类型
    注入的时候StudentServiceImpl 一定要保证是实现IstudentService接口的对象才行!你查看一样是否实现了这个类型! 在setStudentService里面捕捉一下异常!....看是否能正确起动!..
    如果能。说明是这里错了!.一步一步check 。。没问题的!
      

  4.   

    [org.springframework.beans.TypeMismatchException: Failed to convert property value of type [com.wm.spring.service.StudentService] to required type [com.wm.spring.service.IStudentService] for property 'studentService'
      

  5.   

    好人,看看我其他写的对不对:package com.wm.struts.action;import java.util.List;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
    import com.wm.spring.service.IStudentService;
    import com.wm.struts.BaseAction;
    import com.wm.struts.form.StudentForm;public class ItemAction extends BaseAction{ private IStudentService studentService;//生成set方法---1 public void setStudentService(IStudentService studentService) {
    this.studentService = studentService;
    }
     
    public ActionForward showDetail(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws Exception {
    StudentForm sf = (StudentForm)form;
    List studentList = studentService.findAll();
    System.out.println("studentList.size()=="+studentList.size());
     
    if(studentList!=null && studentList.size()>0) {
     request.setAttribute("student", studentList);
     return mapping.findForward("show_detail");
     }
     return mapping.getInputForward();
    }


    }
    补充:IStudentService是接口,
    package com.wm.spring.service;import java.util.List;public interface IStudentService {

    public List findAll();
    }而:StudentService 是它的一个实现类
    package com.wm.spring.service;import java.util.List;import com.wm.spring.dao.IStudentDao;public class StudentService implements IStudentDao { private IStudentDao studentDao; public void setStudentDao(IStudentDao studentDao) {
    try{
    this.studentDao = studentDao;
    }catch(Exception e){
    e.printStackTrace();
    }
    } @Override
    public List findAll() {
     
    return studentDao.findAll();

    }}
      

  6.   

    thank 又 好人,我要睡觉了,爱你~1