异常如下:
[ERROR][org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:215)]-Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring/spring.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.getBeansOfType(DefaultListableBeanFactory.java:308) at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:947) at org.springframework.context.support.AbstractApplicationContext.registerListeners(AbstractApplicationContext.java:701) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:377) 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:4723) at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226) at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) at java.util.concurrent.FutureTask.run(FutureTask.java:166) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:722) Caused by: java.lang.reflect.MalformedParameterizedTypeException at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.validateConstructorArguments(ParameterizedTypeImpl.java:60) at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.<init>(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:816) at com.sun.beans.TypeResolver.prepare(TypeResolver.java:289) at com.sun.beans.TypeResolver.<init>(TypeResolver.java:254) at com.sun.beans.TypeResolver.getTypeResolver(TypeResolver.java:235) 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.<init>(MethodDescriptor.java:72) at java.beans.MethodDescriptor.<init>(MethodDescriptor.java:56) at java.beans.Introspector.getTargetMethodInfo(Introspector.java:1130) at java.beans.Introspector.getBeanInfo(Introspector.java:414) at java.beans.Introspector.getBeanInfo(Introspector.java:161) at org.springframework.beans.CachedIntrospectionResults.<init>(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.getPropertyDescriptors(BeanWrapperImpl.java:259) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.filterPropertyDescriptorsForDependencyCheck(AbstractAutowireCapableBeanFactory.java:1132) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:992) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472) ... 23 more
这是我使用maven多模块去改造普通web项目是遇到的,开始发现单个无依赖区启动maven的web模块正常,加上就会报spring初始化失败,以及各种bean无法被注入
偶然情况下发现我在maven的web模块下发现加入了dubbo的jar包就会报错,上网了解到dubbo自身继承了spring2.x.jar,再看我的web模块缺失使用的spring3.x,
猜想会不会是因为spring2.x与spring3.x冲突呢,然后采取
<dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <version>2.5.3</version> <exclusions> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> </exclusion> <exclusion> <artifactId>netty</artifactId> <groupId>org.jboss.netty</groupId> </exclusion> </exclusions> </dependency>
再次运行,正常,添加依赖后正常