org.springframework.beans.TypeMismatchException

时间:2016-02-08 10:04:20

标签: spring hibernate spring-mvc

获取类型不匹配异常。 我的项目是spring和hibernate集成,我收到错误

Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.util.ArrayList' to required type 'java.lang.Class[]' for property 'annotatedClasses'; nested exception is java.lang.IllegalArgumentException: Cannot find class [com.vrnda.hibernatemappingfile.ProjectDetails]

sdnext-servlet.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"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
  xsi:schemaLocation="
  http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
 http://www.springframework.org/schema/context
 http://www.springframework.org/schema/context/spring-context-3.0.xsd
 http://www.springframework.org/schema/tx
 http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
 http://www.springframework.org/schema/mvc 
 http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
 http://www.springframework.org/schema/jee 
 http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
 http://www.springframework.org/schema/data/mongo
            http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd">

<context:component-scan base-package="com" />



<tx:annotation-driven transaction-manager="hibernateTransactionManager"/>  
<mvc:annotation-driven /> 
<mvc:resources mapping="/images/**" location="/images/**" cache-period="31556926"/>
<mvc:resources mapping="/scripts/**" location="/scripts/**" cache-period="31556926"/>
<mvc:resources mapping="/css/**" location="/css/**" cache-period="31556926"/>
<mvc:resources mapping="/resources/**" location="/**/resources/**,classpath:/META-INF/web-resources/**" cache-period="31556926"/>

<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
<bean id="defaultController" class="org.springframework.web.servlet.mvc.ParameterizableViewController">
  <property name="viewName" value="default" />
</bean>


<bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">

    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://localhost:3306/ProjectManagementTool2" />
    <property name="username" value="root" />
    <property name="password" value="root" />
</bean>
<bean class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" id="sessionFactory">  
< property name="dataSource" ref="dataSource"></property>  
< property name="packagesToscan">  
 < list>     
   < value> com.hibernatemappingfile< /value>
  < /list>  
< /property>  
<  property name="hibernateProperties">  
 < props>  
 < prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>  
  < prop key="hibernate.show_sql">true</prop>  
   < prop key="hibernate.hbm2ddl.auto">update</prop>      
  </props>  
 </property>  
< /bean>  

  < bean class="org.springframework.orm.hibernate3.HibernateTransactionManager" id="hibernateTransactionManager">  
 < property name="sessionFactory" ref="sessionFactory"></property>  
  < /bean> 


    < bean id="jspViewResolver"
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      < property name="viewClass"
        value="org.springframework.web.servlet.view.JstlView" />
     < property name="prefix" value="/WEB-INF/views/" />
     < property name="suffix" value=".jsp" />
   </bean>


<  /beans>

为什么我收到此错误我已经看到所有字段都被激动地映射到该bean。我正在收到该错误。

1 个答案:

答案 0 :(得分:0)

您使用的是Hibernate 3还是Hibernate 4?如果是3,那么它是一个旧项目,你必须使用3?这是我4的配置,它可以工作:

Dim myDict
Set myDict= Server.CreateObject("Multi.Dictionary")
myDict.UniqueKeys = False 

'Fill dictionary with some data
myDict("param1") = "value1"
myDict.Add "param2", "value2"
myDict.Add "param2", "value2.2"

'Get dictionary Keys
Keys = myDict.Keys
Items = myDict.Items

For Z = 0 To UBound(Items)
  Response.Write(Keys(Z) & " " & Items(Z) & "<br>")
Next

上面的值只是给出了所有Model文件所在的包的路径。休息由Spring处理。试试这个,并检查你为什么使用Hibernate 3。