任何建议都会得到赞赏。我很难过......
问题
在我的笔记本电脑上,只要我们的应用程序尝试加载application-config.xml,我就会得到一个java.lang.reflect.MalformedParameterizedTypeException。
EXACT相同的代码适用于我的桌面和同事的台式机/笔记本电脑。但在我的笔记本电脑上它会抛出这个错误。由于我的笔记本电脑和台式机完全相同的开发环境(Mac OS X Leopard上的Eclipse中的Java 1.6 Maven项目),我通过执行以下操作缩小了原因:
在一个地方可能导致此错误但在另一个地方却不会导致此错误?下面是相关bean的片段和错误......
<小时/> 代码段:application-config.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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
...
<bean id="dataServiceRepository" class="com.saic.gnosis.dao.DataServiceDao">
<constructor-arg ref="sessionFactory" />
</bean>
...
<bean id="implementationRepository" class="com.saic.gnosis.dao.ImplementationDao">
<property name="dataServiceRepository" ref="dataServiceRepository" />
<property name="implementationDetailRepository" ref="implementationDetailRepository" />
<property name="implementationStrategyFactory" ref="implementationStrategyFactory" />
</bean>
...
<bean id="implementationStrategyFactory" class="com.saic.gnosis.plant.ImplementationStrategyPlant" />
...
<bean id="implementationDetailRepository" class="com.saic.gnosis.dao.ImplementationDetailDao">
<constructor-arg ref="sessionFactory" />
</bean>
...
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="mysqlDataSource" />
<property name="packagesToScan">
<list>
<value>com.saic.gnosis.model</value>
<value>com.saic.gnosis.model.observable</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.c3p0.min_size">2</prop> <!-- Minimum number of Connections a pool will maintain at any given time. -->
<prop key="hibernate.c3p0.max_size">9</prop> <!-- Maximum number of Connections a pool will maintain at any given time. -->
<prop key="hibernate.c3p0.timeout">10</prop> <!-- Seconds a Connection can remain pooled but unused before being discarded.
Zero means idle connections never expire. -->
<prop key="hibernate.c3p0.max_statements">0</prop> <!-- The size of c3p0's global PreparedStatement cache. If both maxStatements
and maxStatementsPerConnection are zero, statement caching will not be enabled.
If maxStatements is zero but maxStatementsPerConnection is a non-zero value,
statement caching will be enabled, but no global limit will be enforced,
only the per-connection maximum. maxStatements controls the total number
of Statements cached, for all Connections. If set, it should be a fairly
large number, as each pooled Connection requires its own, distinct flock
of cached statements. As a guide, consider how many distinct PreparedStatements
are used frequently in your application, and multiply that number by maxPoolSize
to arrive at an appropriate value. Though maxStatements is the JDBC standard
parameter for controlling statement caching, users may find c3p0's alternative
maxStatementsPerConnection more intuitive to use. -->
</props>
</property>
</bean>
<bean id="mysqlDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://database.com/ourProject" />
<property name="user" value="ourUser" />
<property name="password" value="ourPass" />
<property name="initialPoolSize" value="4" />
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<小时/> 代码段:JUnit错误跟踪:
java.lang.ExceptionInInitializerError
at com.saic.gnosis.updater.task.ConnectionCommandFileWriterTask.<init>(ConnectionCommandFileWriterTask.java:16)
at com.saic.gnosis.updater.CiscoDeviceConfiguratorTest.initializeSpyObjects(CiscoDeviceConfiguratorTest.java:120)
at com.saic.gnosis.updater.CiscoDeviceConfiguratorTest.initializeTestObjects(CiscoDeviceConfiguratorTest.java:110)
at com.saic.gnosis.updater.CiscoDeviceConfiguratorTest.setUp(CiscoDeviceConfiguratorTest.java:105)
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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'implementationRepository' defined in class path resource [beans/application-config.xml]: Cannot resolve reference to bean 'dataServiceRepository' while setting bean property 'dataServiceRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataServiceRepository' defined in class path resource [beans/application-config.xml]: Cannot resolve reference to bean 'sessionFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [beans/application-config.xml]: Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
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:429)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.saic.gnosis.dao.BeanDao.<clinit>(BeanDao.java:35)
... 28 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataServiceRepository' defined in class path resource [beans/application-config.xml]: Cannot resolve reference to bean 'sessionFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [beans/application-config.xml]: Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:495)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:162)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:925)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:835)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)
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.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269)
... 46 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [beans/application-config.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.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269)
... 61 more
Caused by: java.lang.reflect.MalformedParameterizedTypeException
at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.validateConstructorArguments(ParameterizedTypeImpl.java:42)
at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.<init>(ParameterizedTypeImpl.java:35)
at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.make(ParameterizedTypeImpl.java:77)
at sun.reflect.generics.factory.CoreReflectionFactory.makeParameterizedType(CoreReflectionFactory.java:86)
at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:122)
at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:31)
at sun.reflect.generics.repository.ClassRepository.getSuperInterfaces(ClassRepository.java:82)
at java.lang.Class.getGenericInterfaces(Class.java:794)
at org.springframework.core.GenericTypeResolver.getTypeVariableMap(GenericTypeResolver.java:161)
at org.springframework.core.GenericTypeResolver.resolveReturnType(GenericTypeResolver.java:99)
at org.springframework.beans.GenericTypeAwarePropertyDescriptor.getPropertyType(GenericTypeAwarePropertyDescriptor.java:88)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:138)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:386)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1289)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1250)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
... 70 more
<小时/> 编辑:
更新 - 我刚发现另一条线索,我们的数据库相关的JUnit测试都没有工作。在我的桌面上,他们都通过。在我的笔记本电脑上,它们都会失败,但有以下例外:
java.lang.NoSuchMethodError: org.springframework.beans.factory.annotation.InjectionMetadata.<init>(Ljava/lang/Class;Ljava/util/Collection;)V
欢迎任何和所有建议!谢谢!
答案 0 :(得分:17)
我认为你有错误的弹簧罐 - 可能是一个用于弹簧2.5,一个用于3.0。例如,类加载器加载版本3.0的spring-core,其余版本加载2.5。这会导致这样的错误。
我建议您浏览maven依赖关系图并删除所有冗余关系图。如有必要,请在您的pom中使用<exclusions>
。
在此之前清理所有机器上的项目。
答案 1 :(得分:1)
我遇到了同样的问题,另一个措施有所帮助:删除整个.metadata文件夹。稍后从他们的地方导入项目或从svn签出(如果你使用的话)。问题是我们并不真正知道什么元数据被破坏,所以下一步自然就是删除所有元数据。我认为,除了重新安装Eclipse +插件之外,这是最清洁的。
答案 2 :(得分:0)
在尝试在Tomcat中嵌入的Mule ESB上运行Mule服务时,我遇到了类似的错误。解决方案是将JDK从默认值更改为:
java version "1.6.0_18"
OpenJDK Runtime Environment (IcedTea6 1.8.1) (6b18-1.8.1-0ubuntu1)
OpenJDK 64-Bit Server VM (build 16.0-b13, mixed mode)
好老太阳JDK:
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01, mixed mode)
当然,它可能是版本/补丁问题。如果我有时间调查......