spring-无法将类型“ java.util.ArrayList”的属性值转换为属性“ annotatedClasses”的必需类型[java.lang.Class []]

前端之家收集整理的这篇文章主要介绍了spring-无法将类型“ java.util.ArrayList”的属性值转换为属性“ annotatedClasses”的必需类型[java.lang.Class []] 前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我的Spring bean数据库连接myDataSource如下.我正在例外
我该如何解决这个例外. RoomUser的位置正确.
我尝试更改标签,但现在使用.

        
        
        
        
    

 <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionfactorybean">
    <property name="dataSource" ref="myDataSource" />
    <property name="annotatedClasses">
        <list>
            <value>com.room.user.beans.RoomUser</value>
            <value>com.room.user.beans.RoomUserType</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MysqLDialect</prop>
            <prop key="hibernate.show_sql">true</prop> 
        </props>
    </property>
</bean>

例外是:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Initialization of bean Failed; nested exception is 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.room.user.beans.RoomUser]
    at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.doCreateBean(AbstractAutowireCapablebeanfactory.java:483)
    at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory$1.run(AbstractAutowireCapablebeanfactory.java:412)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.createBean(AbstractAutowireCapablebeanfactory.java:383)
    at org.springframework.beans.factory.support.Abstractbeanfactory$1.getObject(Abstractbeanfactory.java:276)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.Abstractbeanfactory.doGetBean(Abstractbeanfactory.java:273)
    at org.springframework.beans.factory.support.Abstractbeanfactory.getBean(Abstractbeanfactory.java:175)
    at org.springframework.beans.factory.support.DefaultListablebeanfactory.preInstantiateSingletons(DefaultListablebeanfactory.java:479)
    at org.springframework.context.support.AbstractApplicationContext.finishbeanfactoryInitialization(AbstractApplicationContext.java:716)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:377)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:427)
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:341)
最佳答案
仅模型类存在问题. spring无法在您的application-context.xml文件中找到类RoomUser

 <list>
        <value>com.room.user.beans.RoomUser</value>
        <value>com.room.user.beans.RoomUserType</value>
    </list>

我也面临着同样的问题.检查RoomUser是否包装正确?

原文链接:https://www.f2er.com/spring/531786.html

猜你在找的Spring相关文章