Maven shade插件ClassNotFoundException

时间:2015-05-17 21:59:42

标签: java hibernate jpa maven-shade-plugin

我正在尝试使用maven shade插件。

我正在使用:Java 7,Spring 4.1.6.RELEASE,Hibernate 4.3.9Final,maven-shade插件版本2.3

我有以下错误。无法弄清楚问题。

    BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [other/project/persistence/jpa/EntityManagerFactoryProvider.class]: Invocation of init method failed; nested exception is java.lang.TypeNotPresentException: Type java.time.LocalTime not present
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:523)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:512)
    at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:1052)
    at org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors(BeanFactoryUtils.java:227)
    at org.springframework.data.jpa.repository.config.JpaMetamodelMappingContextFactoryBean.getMetamodels(JpaMetamodelMappingContextFactoryBean.java:85)
    at org.springframework.data.jpa.repository.config.JpaMetamodelMappingContextFactoryBean.createInstance(JpaMetamodelMappingContextFactoryBean.java:56)
    at org.springframework.data.jpa.repository.config.JpaMetamodelMappingContextFactoryBean.createInstance(JpaMetamodelMappingContextFactoryBean.java:26)
Caused by: java.lang.TypeNotPresentException: Type java.time.LocalTime not present
    at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(Unknown Source)
    at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Unknown Source)
    at sun.reflect.generics.tree.ClassTypeSignature.accept(Unknown Source)
    at sun.reflect.generics.visitor.Reifier.reifyTypeArguments(Unknown Source)
    at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Unknown Source)
    at sun.reflect.generics.tree.ClassTypeSignature.accept(Unknown Source)
    at sun.reflect.generics.repository.ClassRepository.getSuperInterfaces(Unknown Source)
    at java.lang.Class.getGenericInterfaces(Unknown Source)
    at org.hibernate.cfg.AttributeConverterDefinition.extractAttributeConverterParameterizedType(AttributeConverterDefinition.java:85)
    at org.hibernate.cfg.AttributeConverterDefinition.<init>(AttributeConverterDefinition.java:52)
    at org.hibernate.cfg.Configuration.addAttributeConverter(Configuration.java:2729)
    at org.hibernate.cfg.Configuration.addAttributeConverter(Configuration.java:2673)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.buildHibernateConfiguration(EntityManagerFactoryBuilderImpl.java:1153)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:853)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
    at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:425)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:849)
    at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:152)
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
]       
Caused by: java.lang.ClassNotFoundException: java.time.LocalTime
    at java.net.URLClassLoader$1.run(Unknown Source)
]

修改: 发现问题,但仍然没有解决方案:我正在使用org.threeten.threetenbp中的LocalDate,我已经设置了jadira.usertype.autoRegisterUserTypes = true。正如我所说,从IntelliJ运行主类时工作正常,但在执行jar时却没有。

2 个答案:

答案 0 :(得分:0)

Java8中出现了

java.time.LocalTime ,因此您所依赖的某些库可能正在使用Java8的类(根据您的堆栈跟踪,这是Hibernate)

答案 1 :(得分:0)

您对Java {8>中引入的java.lang.LocalTime具有依赖性。

由于您使用的是Java 7,因此获得ClassNotFoundException。切换到Java 8或替换引入依赖项的库。