我使用Spring和Hibernate & & JPA的web應用程序,運行在Tomcat 在我的本地計算機(Ubuntu的14.04),這一偉大工程。 在服務器(?Ubuntu服務器14.04 - 沒有任何圖形用戶界面,但不應該的問題對Hibernate ...或者),對Web應用程序啓動時拋出以下異常:休眠的entityManagerFactory初始化拋出的ExceptionInInitializerError java.lang.ClassCastException
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/spring-database.xml]: Invocation of init method failed; nested exception is java.lang.ExceptionInInitializerEr$
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1568)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:540)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:956)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:747)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4751)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5175)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:919)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1704)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:340)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:240)
at org.hibernate.metamodel.internal.ClassLoaderAccessImpl.classForName(ClassLoaderAccessImpl.java:68)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.makeTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:261)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.getType(JavaTypeDescriptorRepositoryImpl.java:173)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.toTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:569)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.extractFields(JavaTypeDescriptorRepositoryImpl.java:479)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.makeTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:315)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.makeTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:261)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.getType(JavaTypeDescriptorRepositoryImpl.java:173)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.toTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:569)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.fromMethod(JavaTypeDescriptorRepositoryImpl.java:650)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.extractMethods(JavaTypeDescriptorRepositoryImpl.java:616)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.makeTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:316)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.makeTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:261)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.getType(JavaTypeDescriptorRepositoryImpl.java:173)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.toTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:569)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.extractFields(JavaTypeDescriptorRepositoryImpl.java:479)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.makeTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:315)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.makeTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:261)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.getType(JavaTypeDescriptorRepositoryImpl.java:173)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.extractSuper(JavaTypeDescriptorRepositoryImpl.java:442)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.makeTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:307)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.makeTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:261)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.getType(JavaTypeDescriptorRepositoryImpl.java:173)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.toTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:569)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.extractFields(JavaTypeDescriptorRepositoryImpl.java:479)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.makeTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:315)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.makeTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:261)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.getType(JavaTypeDescriptorRepositoryImpl.java:173)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.toTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:569)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.fromMethod(JavaTypeDescriptorRepositoryImpl.java:654)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.extractMethods(JavaTypeDescriptorRepositoryImpl.java:616)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.makeTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:316)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.makeTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:261)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.getType(JavaTypeDescriptorRepositoryImpl.java:173)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.toTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:569)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.fromMethod(JavaTypeDescriptorRepositoryImpl.java:654)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.extractMethods(JavaTypeDescriptorRepositoryImpl.java:616)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.makeTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:316)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.makeTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:261)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.getType(JavaTypeDescriptorRepositoryImpl.java:173)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.toTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:569)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.fromMethod(JavaTypeDescriptorRepositoryImpl.java:650)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.extractMethods(JavaTypeDescriptorRepositoryImpl.java:616)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.makeTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:316)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.makeTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:261)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.getType(JavaTypeDescriptorRepositoryImpl.java:173)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.toTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:569)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.extractFields(JavaTypeDescriptorRepositoryImpl.java:479)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.makeTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:315)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.makeTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:261)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.getType(JavaTypeDescriptorRepositoryImpl.java:173)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.toTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:569)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.extractFields(JavaTypeDescriptorRepositoryImpl.java:479)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.makeTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:315)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.makeTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:261)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.makeTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:292)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.makeTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:261)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.getType(JavaTypeDescriptorRepositoryImpl.java:173)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.toTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:569)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.fromMethod(JavaTypeDescriptorRepositoryImpl.java:650)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.extractMethods(JavaTypeDescriptorRepositoryImpl.java:616)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.makeTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:292)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.makeTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:261)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.getType(JavaTypeDescriptorRepositoryImpl.java:173)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.extractInterfaces(JavaTypeDescriptorRepositoryImpl.java:453)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.makeTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:308)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.makeTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:261)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.getType(JavaTypeDescriptorRepositoryImpl.java:173)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.extractSuper(JavaTypeDescriptorRepositoryImpl.java:442)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.makeTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:307)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.makeTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:261)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.getType(JavaTypeDescriptorRepositoryImpl.java:173)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.toTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:569)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.fromMethod(JavaTypeDescriptorRepositoryImpl.java:650)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.extractMethods(JavaTypeDescriptorRepositoryImpl.java:616)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.makeTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:316)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.makeTypeDescriptor(JavaTypeDescriptorRepositoryImpl.java:261)
at org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl.getType(JavaTypeDescriptorRepositoryImpl.java:173)
at org.hibernate.metamodel.source.internal.annotations.util.EntityHierarchyBuilder.findHierarchyRootDescriptors(EntityHierarchyBuilder.java:140)
at org.hibernate.metamodel.source.internal.annotations.util.EntityHierarchyBuilder.process(EntityHierarchyBuilder.java:102)
at org.hibernate.metamodel.source.internal.annotations.util.EntityHierarchyBuilder.createEntityHierarchies(EntityHierarchyBuilder.java:80)
at org.hibernate.metamodel.source.internal.annotations.AnnotationMetadataSourceProcessor.extractEntityHierarchies(AnnotationMetadataSourceProcessor.java:104)
at org.hibernate.metamodel.internal.MetadataBuildingProcess.processMappings(MetadataBuildingProcess.java:533)
at org.hibernate.metamodel.internal.MetadataBuildingProcess.build(MetadataBuildingProcess.java:231)
at org.hibernate.metamodel.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:251)
at org.hibernate.metamodel.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:74)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:190)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:156)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider$1.<init>(SpringHibernateJpaPersistenceProvider.java:49)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:49)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:341)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1627)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1564)
... 25 more
Caused by: java.lang.ClassCastException: sun.awt.HeadlessToolkit cannot be cast to sun.awt.SunToolkit
at sun.awt.datatransfer.DataTransferer.getInstance(DataTransferer.java:275)
at sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher.<clinit>(SunDropTargetContextPeer.java:751)
... 132 more
事情我不明白爲什麼Hibernate需要sun.awt中的任何東西?
我的彈簧database.xml:
<?xml version="1.0" encoding="UTF-8"?>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://${database.location}:${database.port}/${database.dbname}?zeroDateTimeBehavior=convertToNull&characterEncoding=utf8"/>
<property name="username" value="${database.username}"/>
<property name="password" value="${database.password}"/>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" />
<property name="persistenceUnitName" value="pu" />
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
<property name="jpaDialect" ref="jpaDialect" />
</bean>
<bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect" />
<property name="database" value="MYSQL" />
<property name="showSql" value="false" />
</bean>
<bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
<property name="dataSource" ref="dataSource" />
<property name="jpaDialect" ref="jpaDialect" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
而且我persistance.xml:
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="pu" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<!-- model objects removed -->
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://${database.location}:${database.port}/${database.dbname}?zeroDateTimeBehavior=convertToNull&characterEncoding=utf8"/>
<property name="javax.persistence.jdbc.user" value="${database.username}"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.password" value="${database.password}"/>
</properties>
(DB配置從Maven的設置)
使用Hibernate依賴:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>[4.3.6.Final,)</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>[4.3.6.Final,)</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>[4.3.6.Final,)</version>
</dependency>
編輯 以前用過java8u20 複製java8u11從我的本地補償安裝,異常改變:
Caused by: java.lang.NullPointerException
at sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher.<clinit>(SunDropTargetContextPeer.java:744)
... 125 more
嘗試添加虛擬顯示的環境變量到/ etc /環境,沒有幫助... – SzaboAdam 2014-09-05 14:55:34
安裝XVFB ......沒有結果的問題... – SzaboAdam 2014-09-05 15:02:00
安裝GUI修復它(sudo apt-get install --no-install-recommended lubuntu-desktop),但我確定有更好的解決方案... – SzaboAdam 2014-09-05 15:43:36