gpt4 book ai didi

java - 创建名为 'mySessionFactory' 的 bean 时出错 bean 初始化失败;嵌套异常是 MalformedParameterizedTypeException

转载 作者:行者123 更新时间:2023-12-01 18:36:06 27 4
gpt4 key购买 nike

我正在尝试使用 hibernate 4 配置 spring。但我不断收到

SEVERE: Context initialization failedorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480)    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)    at java.security.AccessController.doPrivileged(Native Method)    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423)    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)    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:754)    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)    at java.lang.reflect.Method.invoke(Method.java:601)    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)Caused by: java.lang.reflect.MalformedParameterizedTypeException    at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.validateConstructorArguments(ParameterizedTypeImpl.java:60)    at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.(ParameterizedTypeImpl.java:53)    at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.make(ParameterizedTypeImpl.java:95)    at sun.reflect.generics.factory.CoreReflectionFactory.makeParameterizedType(CoreReflectionFactory.java:105)    at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:140)    at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)    at sun.reflect.generics.repository.ClassRepository.getSuperInterfaces(ClassRepository.java:100)    at java.lang.Class.getGenericInterfaces(Class.java:814)    at com.sun.beans.TypeResolver.prepare(TypeResolver.java:278)    at com.sun.beans.TypeResolver.(TypeResolver.java:243)    at com.sun.beans.TypeResolver.resolve(TypeResolver.java:172)    at com.sun.beans.TypeResolver.resolveInClass(TypeResolver.java:93)    at java.beans.FeatureDescriptor.getParameterTypes(FeatureDescriptor.java:387)    at java.beans.MethodDescriptor.setMethod(MethodDescriptor.java:114)    at java.beans.MethodDescriptor.(MethodDescriptor.java:72)    at java.beans.MethodDescriptor.(MethodDescriptor.java:56)    at java.beans.Introspector.getTargetMethodInfo(Introspector.java:1150)    at java.beans.Introspector.getBeanInfo(Introspector.java:433)    at java.beans.Introspector.getBeanInfo(Introspector.java:174)    at org.springframework.beans.CachedIntrospectionResults.(CachedIntrospectionResults.java:220)    at org.springframework.beans.CachedIntrospectionResults.forClass(CachedIntrospectionResults.java:144)    at org.springframework.beans.BeanWrapperImpl.getCachedIntrospectionResults(BeanWrapperImpl.java:252)    at org.springframework.beans.BeanWrapperImpl.getPropertyDescriptorInternal(BeanWrapperImpl.java:282)    at org.springframework.beans.BeanWrapperImpl.isWritableProperty(BeanWrapperImpl.java:333)    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1247)    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)    ... 29 moreFeb 22, 2014 12:03:13 PM org.apache.catalina.core.StandardContext listenerStartSEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListenerorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480)    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)    at java.security.AccessController.doPrivileged(Native Method)    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423)    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)    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:754)    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)    at java.lang.reflect.Method.invoke(Method.java:601)    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)Caused by: java.lang.reflect.MalformedParameterizedTypeException    at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.validateConstructorArguments(ParameterizedTypeImpl.java:60)    at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.(ParameterizedTypeImpl.java:53)    at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.make(ParameterizedTypeImpl.java:95)    at sun.reflect.generics.factory.CoreReflectionFactory.makeParameterizedType(CoreReflectionFactory.java:105)    at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:140)    at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)    at sun.reflect.generics.repository.ClassRepository.getSuperInterfaces(ClassRepository.java:100)    at java.lang.Class.getGenericInterfaces(Class.java:814)    at com.sun.beans.TypeResolver.prepare(TypeResolver.java:278)    at com.sun.beans.TypeResolver.(TypeResolver.java:243)    at com.sun.beans.TypeResolver.resolve(TypeResolver.java:172)    at com.sun.beans.TypeResolver.resolveInClass(TypeResolver.java:93)    at java.beans.FeatureDescriptor.getParameterTypes(FeatureDescriptor.java:387)    at java.beans.MethodDescriptor.setMethod(MethodDescriptor.java:114)    at java.beans.MethodDescriptor.(MethodDescriptor.java:72)    at java.beans.MethodDescriptor.(MethodDescriptor.java:56)    at java.beans.Introspector.getTargetMethodInfo(Introspector.java:1150)    at java.beans.Introspector.getBeanInfo(Introspector.java:433)    at java.beans.Introspector.getBeanInfo(Introspector.java:174)    at org.springframework.beans.CachedIntrospectionResults.(CachedIntrospectionResults.java:220)    at org.springframework.beans.CachedIntrospectionResults.forClass(CachedIntrospectionResults.java:144)    at org.springframework.beans.BeanWrapperImpl.getCachedIntrospectionResults(BeanWrapperImpl.java:252)    at org.springframework.beans.BeanWrapperImpl.getPropertyDescriptorInternal(BeanWrapperImpl.java:282)    at org.springframework.beans.BeanWrapperImpl.isWritableProperty(BeanWrapperImpl.java:333)    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1247)    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)    ... 29 more

I am using following jar files

antlr-2.7.7.jar
commons-dbcp-1.4.jar
commons-logging-1.1.3.jar
commons-pool-1.5.jar
cruze-1.0.10.jar
dom4j-1.6.1.jar
hibernate-commons-annotations-4.0.4.Final.jar
hibernate-core-4.3.0.Final.jar
hibernate-jpa-2.1-api-1.0.0.Final.jar
jandex-1.1.0.Final.jar
javassist-3.18.1-GA.jar
javax.inject-1.jar
jboss-logging-3.1.3.GA.jar
jboss-logging-annotations-1.2.0.Beta1.jar
jboss-transaction-api_1.2_spec-1.0.0.Final.jar
mysql-connector-java-5.1.6-bin.jar
primefaces-4.0.jar
spring-2.5.6.jar
spring-data-commons-core-1.4.1.RELEASE.jar
spring-orm-4.0.0.RELEASE.jar

我没有使用 Maven 或 Ant。

我的 applicationContext.xml 文件是

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
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-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd">


<bean id="cab" class="com.beans.Cab" scope="session" autowire="byType"></bean>
<bean id="isBean" class="assets.impl.SpringBean" autowire="byType"></bean>


<bean id="myDataSource" class = "org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/rendacab?useUnicode=true"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</bean>


<bean id="mySessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="myDataSource"/>
<property name="packagesToScan" value="com.rent.cab.entity"/>
<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">create</prop>
</props>
</property>
</bean>

</beans>

我搜索过其他论坛,包括 stackoverflow,但那里给出的解决方案对我没有帮助。我一次又一次地遇到同样的异常。

请帮帮我问候

最佳答案

您正在混合 spring 版本:

  1. Spring 2.5.6
  2. Spring-ORM 4.0.0

就像之前讨论的那样:

http://forum.spring.io/forum/spring-projects/data/66790-localsessionfactorybean-malformedparameterizedtypeexception

Correct version of Spring and Hibernate and required dependencies...Exception due to dependencies

它抛出一个MalformedParameterizedTypeException

您必须将 spring (核心)依赖项升级到 >=3.1.x 和 spring-orm >=3.1.x (3.0.x 不支持 hibernate 4 )。

我使用以下依赖项完成了测试:

失败:(MalformedParameterizedTypeException)

<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.6</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.0.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.29</version>
</dependency>
</dependencies>

成功:

<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.1.0.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.0.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.29</version>
</dependency>
</dependencies>

PS:成功后我将使用最小的 spring core 版本,但如果您使用 spring orm 4,您也可以使用 spring core 4。

关于java - 创建名为 'mySessionFactory' 的 bean 时出错 bean 初始化失败;嵌套异常是 MalformedParameterizedTypeException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21951189/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com