将 pf4j 与弹簧数据一起使用时,我遇到异常。
我的项目结构是一个Web应用程序 org.home.server.communication (war),它部署到Tomcat并使用 Spring MVC 。它加载 pf4j 插件 - org.home.server.core (jar)。 它完美无缺,直到我尝试在 org.home.server.core (插件项目)中使用 spring-data-mongodb 并尝试使用 MongoRepository / CrudRepository / 存储库即可。
在插件构造函数中我做:
public PluginStarter(final PluginWrapper wrapper) {
super(wrapper);
appContext.setId("Core-Module-Context");
appContext.setClassLoader(this.getClass().getClassLoader());
appContext.getBeanFactory().setBeanClassLoader(this.getClass().getClassLoader());
appContext.register(CoreRootConfig.class);
appContext.refresh();
mApplicationContext = appContext;
}
但是当我在插件应用程序中定义任何存储库并尝试从我的主应用程序启动它时,它会崩溃。这是存储库示例:
public interface ConnectorRepository extends MongoRepository<Connector, String> {}
当我不使用 pf4j 和jsut run jar作为独立应用程序时,一切正常。所以,我认为问题不在于 Spring Framework 。也许有人已经尝试在 pf4j 中使用 Spring-Data 和存储库并遇到此问题。
也许有人可以指出我下一步去哪看?
D|DefaultListableBeanFactory |Invoking afterPropertiesSet() on bean with name 'connectorRepository'
D|PluginClassLoader |Received request to load class 'org.springframework.data.repository.core.support.AbstractRepositoryMetadata'
D|PluginClassLoader |Found class 'org.springframework.data.repository.core.support.AbstractRepositoryMetadata' in plugin classpath
D|PluginClassLoader |Received request to load class 'org.springframework.data.repository.core.support.DefaultRepositoryMetadata'
D|PluginClassLoader |Found class 'org.springframework.data.repository.core.support.DefaultRepositoryMetadata' in plugin classpath
D|PluginClassLoader |Received request to load class 'org.springframework.data.repository.core.support.AnnotationRepositoryMetadata'
D|PluginClassLoader |Found class 'org.springframework.data.repository.core.support.AnnotationRepositoryMetadata' in plugin classpath
D|PluginClassLoader |Received request to load class 'org.springframework.data.repository.query.QueryLookupStrategy'
D|PluginClassLoader |Found class 'org.springframework.data.repository.query.QueryLookupStrategy' in plugin classpath
D|PluginClassLoader |Received request to load class 'org.springframework.data.mongodb.repository.query.MongoEntityInformation'
D|PluginClassLoader |Found class 'org.springframework.data.mongodb.repository.query.MongoEntityInformation' in plugin classpath
D|PluginClassLoader |Received request to load class 'org.springframework.data.repository.util.NullableWrapper'
D|PluginClassLoader |Found class 'org.springframework.data.repository.util.NullableWrapper' in plugin classpath
D|PluginClassLoader |Received request to load class 'org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryCollectingQueryCreationListener'
D|PluginClassLoader |Found class 'org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryCollectingQueryCreationListener' in plugin classpath
D|PluginClassLoader |Received request to load class 'org.springframework.data.repository.core.CrudMethods'
D|PluginClassLoader |Found class 'org.springframework.data.repository.core.CrudMethods' in plugin classpath
D|PluginClassLoader |Received request to load class 'org.springframework.core.GenericTypeResolver$TypeVariableMapVariableResolver'
D|PluginClassLoader |Found class 'org.springframework.core.GenericTypeResolver$TypeVariableMapVariableResolver' in plugin classpath
D|PluginClassLoader |Received request to load class 'org.springframework.data.util.ParameterizedTypeInformation'
D|PluginClassLoader |Received request to load class 'org.springframework.data.util.ParentTypeAwareTypeInformation'
D|PluginClassLoader |Found class 'org.springframework.data.util.ParentTypeAwareTypeInformation' in plugin classpath
D|PluginClassLoader |Found class 'org.springframework.data.util.ParameterizedTypeInformation' in plugin classpath
D|PluginClassLoader |Received request to load class 'org.springframework.data.util.TypeVariableTypeInformation'
D|PluginClassLoader |Found class 'org.springframework.data.util.TypeVariableTypeInformation' in plugin classpath
D|PluginClassLoader |Received request to load class 'org.springframework.data.repository.core.support.RepositoryFactorySupport$RepositoryInformationCacheKey'
D|PluginClassLoader |Found class 'org.springframework.data.repository.core.support.RepositoryFactorySupport$RepositoryInformationCacheKey' in plugin classpath
D|PluginClassLoader |Received request to load class 'org.springframework.data.repository.core.support.DefaultRepositoryInformation'
D|PluginClassLoader |Found class 'org.springframework.data.repository.core.support.DefaultRepositoryInformation' in plugin classpath
D|PluginClassLoader |Received request to load class 'org.springframework.data.querydsl.QueryDslUtils'
D|PluginClassLoader |Found class 'org.springframework.data.querydsl.QueryDslUtils' in plugin classpath
D|PluginClassLoader |Received request to load class 'com.mysema.query.types.Predicate'
D|PluginClassLoader |Look in dependencies for class 'com.mysema.query.types.Predicate'
D|PluginClassLoader |Couldn't find class '{}' in plugin classpath. Delegating to parent
D|PluginClassLoader |Received request to load class 'com.mysema.query.types$Predicate'
D|PluginClassLoader |Look in dependencies for class 'com.mysema.query.types$Predicate'
D|PluginClassLoader |Couldn't find class '{}' in plugin classpath. Delegating to parent
D|PluginClassLoader |Received request to load class 'org.springframework.data.mongodb.repository.support.SimpleMongoRepository'
D|PluginClassLoader |Found class 'org.springframework.data.mongodb.repository.support.SimpleMongoRepository' in plugin classpath
D|PluginClassLoader |Received request to load class 'org.springframework.data.domain.Sort'
D|PluginClassLoader |Found class 'org.springframework.data.domain.Sort' in plugin classpath
D|PluginClassLoader |Received request to load class 'org.springframework.data.domain.Pageable'
D|PluginClassLoader |Found class 'org.springframework.data.domain.Pageable' in plugin classpath
D|PluginClassLoader |Received request to load class 'org.springframework.data.domain.Page'
D|PluginClassLoader |Received request to load class 'org.springframework.data.domain.Slice'
D|PluginClassLoader |Found class 'org.springframework.data.domain.Slice' in plugin classpath
D|PluginClassLoader |Found class 'org.springframework.data.domain.Page' in plugin classpath
D|PluginClassLoader |Received request to load class 'java.util.AbstractSet'
D|PluginClassLoader |Look in dependencies for class 'java.util.AbstractSet'
D|PluginClassLoader |Couldn't find class '{}' in plugin classpath. Delegating to parent
D|PluginClassLoader |Received request to load class 'org.springframework.data.mongodb.core.mapping.BasicMongoPersistentEntity$MongoPersistentPropertyComparator'
D|PluginClassLoader |Found class 'org.springframework.data.mongodb.core.mapping.BasicMongoPersistentEntity$MongoPersistentPropertyComparator' in plugin classpath
D|PluginClassLoader |Received request to load class 'org.springframework.data.mapping.model.PreferredConstructorDiscoverer'
D|PluginClassLoader |Found class 'org.springframework.data.mapping.model.PreferredConstructorDiscoverer' in plugin classpath
D|PluginClassLoader |Received request to load class 'org.springframework.data.util.ReflectionUtils'
D|PluginClassLoader |Found class 'org.springframework.data.util.ReflectionUtils' in plugin classpath
D|PluginClassLoader |Received request to load class 'org.springframework.data.util.ReflectionUtils$DescribedFieldFilter'
D|PluginClassLoader |Found class 'org.springframework.data.util.ReflectionUtils$DescribedFieldFilter' in plugin classpath
D|PluginClassLoader |Received request to load class 'org.springframework.core.NestedExceptionUtils'
D|PluginClassLoader |Found class 'org.springframework.core.NestedExceptionUtils' in plugin classpath
D|DefaultListableBeanFactory |Retrieved dependent beans for bean '(inner bean)#a303d13': [connectorRepository]
D|DefaultListableBeanFactory |Retrieved dependent beans for bean '(inner bean)#72adbe38': [(inner bean)#a303d13]
D|DefaultListableBeanFactory |Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@144f3ec6: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,coreRootConfig,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor,org.home.server.core.module.config.CoreMongoDBConfig,mongo,mongoTemplate,org.springframework.data.mongodb.repository.config.MongoRepositoryConfigurationExtension#0,org.springframework.data.repository.core.support.RepositoryInterfaceAwareBeanPostProcessor#0,mongoMappingContext,connectorRepository]; root of factory hierarchy
D|DisposableBeanAdapter |Invoking destroy() on bean with name 'mongo'
D|PluginClassLoader |Received request to load class 'com.mongodb.ConcurrentLinkedDeque$CLDIterator'
D|PluginClassLoader |Found class 'com.mongodb.ConcurrentLinkedDeque$CLDIterator' in plugin classpath
D|DisposableBeanAdapter |Invoking destroy() on bean with name 'org.home.server.core.module.config.CoreMongoDBConfig'
D|DisposableBeanAdapter |Invoking destroy() on bean with name 'coreRootConfig'
E|DefaultExtensionFactory |null
java.lang.reflect.InvocationTargetException: null
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_20]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_20]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_20]
at java.lang.reflect.Constructor.newInstance(Constructor.java:408) ~[na:1.8.0_20]
at ro.fortsoft.pf4j.DefaultPluginFactory.create(DefaultPluginFactory.java:61) ~[DefaultPluginFactory.class:0.9.0]
at ro.fortsoft.pf4j.PluginWrapper.getPlugin(PluginWrapper.java:63) [PluginWrapper.class:0.9.0]
at ro.fortsoft.pf4j.DefaultPluginManager.startPlugins(DefaultPluginManager.java:213) [DefaultPluginManager.class:0.9.0]
at org.home.server.communication.Starter.contextInitialized(Starter.java:86) [Starter.class:na]
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4758) [catalina.jar:8.0.9]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5184) [catalina.jar:8.0.9]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:8.0.9]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724) [catalina.jar:8.0.9]
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700) [catalina.jar:8.0.9]
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714) [catalina.jar:8.0.9]
at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1588) [catalina.jar:8.0.9]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_20]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_20]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_20]
at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_20]
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300) [tomcat-coyote.jar:8.0.9]
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) [na:1.8.0_20]
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) [na:1.8.0_20]
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:463) [catalina.jar:8.0.9]
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:413) [catalina.jar:8.0.9]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_20]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_20]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_20]
at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_20]
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300) [tomcat-coyote.jar:8.0.9]
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) [na:1.8.0_20]
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) [na:1.8.0_20]
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1466) [na:1.8.0_20]
at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76) [na:1.8.0_20]
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1307) [na:1.8.0_20]
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1399) [na:1.8.0_20]
at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:828) [na:1.8.0_20]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_20]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_20]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_20]
at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_20]
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:323) [na:1.8.0_20]
at sun.rmi.transport.Transport$1.run(Transport.java:178) [na:1.8.0_20]
at sun.rmi.transport.Transport$1.run(Transport.java:175) [na:1.8.0_20]
at java.security.AccessController.doPrivileged(Native Method) [na:1.8.0_20]
at sun.rmi.transport.Transport.serviceCall(Transport.java:174) [na:1.8.0_20]
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:557) [na:1.8.0_20]
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:812) [na:1.8.0_20]
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:671) [na:1.8.0_20]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_20]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_20]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_20]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'connectorRepository': Invocation of init method failed; nested exception is java.lang.ExceptionInInitializerError
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553) ~ [AbstractAutowireCapableBeanFactory.class:4.0.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) ~[AbstractAutowireCapableBeanFactory.class:4.0.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) ~[AbstractAutowireCapableBeanFactory.class:4.0.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302) ~[AbstractBeanFactory$1.class:4.0.6.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[DefaultSingletonBeanRegistry.class:4.0.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298) ~[AbstractBeanFactory.class:4.0.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) ~[AbstractBeanFactory.class:4.0.6.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:684) ~[DefaultListableBeanFactory.class:4.0.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760) ~[AbstractApplicationContext.class:4.0.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) ~[AbstractApplicationContext.class:4.0.6.RELEASE]
at org.home.server.core.module.CoreModule.<init>(CoreModule.java:90) ~[na:na]
at org.home.server.core.PluginStarter.<init>(PluginStarter.java:56) ~[na:na]
... 51 common frames omitted
Caused by: java.lang.ExceptionInInitializerError: null
at org.springframework.data.mapping.model.BasicPersistentEntity.<init>(BasicPersistentEntity.java:85) ~[na:na]
at org.springframework.data.mongodb.core.mapping.BasicMongoPersistentEntity.<init>(BasicMongoPersistentEntity.java:67) ~[na:na]
at org.springframework.data.mongodb.core.mapping.MongoMappingContext.createPersistentEntity(MongoMappingContext.java:89) ~[na:na]
at org.springframework.data.mongodb.core.mapping.MongoMappingContext.createPersistentEntity(MongoMappingContext.java:37) ~[na:na]
at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:280) ~[na:na]
at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:181) ~[na:na]
at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:141) ~[na:na]
at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:67) ~[na:na]
at org.springframework.data.mongodb.repository.support.MongoRepositoryFactory.getEntityInformation(MongoRepositoryFactory.java:141) ~[na:na]
at org.springframework.data.mongodb.repository.support.MongoRepositoryFactory.getTargetRepository(MongoRepositoryFactory.java:83) ~[na:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:158) ~[na:na]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:224) ~[na:na]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:210) ~[na:na]
at org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean.afterPropertiesSet(MongoRepositoryFactoryBean.java:108) ~[na:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612) ~[AbstractAutowireCapableBeanFactory.class:4.0.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549) ~[AbstractAutowireCapableBeanFactory.class:4.0.6.RELEASE]
... 62 common frames omitted
Caused by: java.lang.ClassCastException: org.springframework.core.DefaultParameterNameDiscoverer cannot be cast to org.springframework.core.ParameterNameDiscoverer
at org.springframework.data.mapping.model.PreferredConstructorDiscoverer.<clinit>(PreferredConstructorDiscoverer.java:41) ~[na:na]
... 78 common frames omitted
I|Starter |Context destruction has began.
I|AnnotationConfigWebApplicationContext |Closing Root WebApplicationContext: startup date [Fri Sep 05 09:15:09 CEST 2014]; root of context hierarchy
D|DefaultListableBeanFactory |Returning cached instance of singleton bean 'lifecycleProcessor'
D|DefaultListableBeanFactory |Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1fbb2adf: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,rootConfig,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor]; root of factory hierarchy
答案 0 :(得分:0)
问题解决了。
这是依赖冲突。 Spring框架jar包含在两个项目中(war加载pf4j插件和插件应用程序本身),这导致:
Caused by: java.lang.ClassCastException:
org.springframework.core.DefaultParameterNameDiscoverer
cannot be cast to org.springframework.core.ParameterNameDiscoverer
at org.springframework.data.mapping.model.PreferredConstructorDiscoverer.<clinit>
(PreferredConstructorDiscoverer.java:41)
在排除冲突的jar后,一切正常,在这种情况下,它是springframework-core.jar,来自插件应用程序构建。