本文介绍了Spring Boot Eclipse Maven WAS:创建名称为'entityManagerFactory'的bean时出错,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Web应用程序部署到WAS8,但收到此错误消息.请帮忙!

I am trying to deploy my web app to WAS8 but I get this error message. Please help!!

我的应用程序在命令"mvn spring-boot:run"上运行时运行良好.我已经签出了许多与如何将Spring Boot项目部署到WAS8有关的网站,但是我仍然无法完成这项工作..我不知道这里缺少什么.我是Websphere的新手,并且我不太了解Websphere的配置.请帮忙!

my application work fine when running on command : "mvn spring-boot:run".I have checked out many website related with how to deploy spring boot project to WAS8, yet I am still failing to make this work.. I do not know what is missing here. I am new to websphere and i do not know much of the configuration for websphere. Please help!!

[10/26/16 15:56:24:429 SGT] 000002f9 SystemOut     O 2016-10-26 15:56:24.428  WARN 21564 --- [hreadPool : 707] a.i.JarInputStreamBasedArchiveDescriptor : HHH015010: Unable to find file (ignored): bundleresource://104.fwk1269020858/

java.lang.NullPointerException: in is null
    at java.util.zip.ZipInputStream.<init>(ZipInputStream.java:75) ~[na:1.6.0]
    at java.util.jar.JarInputStream.<init>(JarInputStream.java:69) ~[na:1.6.0]
    at java.util.jar.JarInputStream.<init>(JarInputStream.java:55) ~[na:1.6.0]
    at org.hibernate.jpa.boot.archive.internal.JarInputStreamBasedArchiveDescriptor.visitArchive(JarInputStreamBasedArchiveDescriptor.java:73) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
    at org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl.scan(AbstractScannerImpl.java:72) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.scan(EntityManagerFactoryBuilderImpl.java:725) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:221) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:188) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:54) [spring-orm-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343) [spring-orm-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    ...

[10/26/16 15:56:24:847 SGT] 000002f9 SystemOut     O 2016-10-26 15:56:24.846  INFO 21564 --- [hreadPool : 707] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
[10/26/16 15:56:25:192 SGT] 000002f9 SystemOut     O 2016-10-26 15:56:25.192  INFO 21564 --- [hreadPool : 707] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.SQLServerDialect
[10/26/16 15:56:25:232 SGT] 000002f9 SystemOut     O 2016-10-26 15:56:25.232  INFO 21564 --- [hreadPool : 707] o.h.e.jdbc.internal.LobCreatorBuilder    : HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
[10/26/16 15:56:25:528 SGT] 000002f9 SystemOut     O 2016-10-26 15:56:25.528  WARN 21564 --- [hreadPool : 707] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax/persistence/Table.indexes()[Ljavax/persistence/Index;
[10/26/16 15:56:25:546 SGT] 000002f9 SystemOut     O 2016-10-26 15:56:25.546 ERROR 21564 --- [hreadPool : 707] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax/persistence/Table.indexes()[Ljavax/persistence/Index;
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    ... ...
Caused by: java.lang.NoSuchMethodError: javax/persistence/Table.indexes()[Ljavax/persistence/Index;
    at org.hibernate.cfg.annotations.EntityBinder.processComplementaryTableDefinitions(EntityBinder.java:973) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
    ...

这是我的pom.xml

Here is my pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.5.RELEASE</version>
</parent>

<groupId>com.aiahk.FileUpload</groupId>
<artifactId>testUpload</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
        <!-- for java 6 -->
        <exclusions>
            <exclusion>
                <groupId>javax.transaction</groupId>
                <artifactId>javax.transaction-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <!-- embedded tomcat -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- BEGIN downgrade some jar to use java 6 -->
    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-juli</artifactId>
        <version>${tomcat.version}</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.6.1</version><!--$NO-MVN-MAN-VER$-->
    </dependency>
    <dependency>
        <groupId>org.jboss.spec.javax.transaction</groupId>
        <artifactId>jboss-transaction-api_1.2_spec</artifactId>
        <version>1.0.0.Final</version>
    </dependency>
    <!-- END downgrade some jar to use java 6 -->


    <!-- for jsp use -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
    </dependency>

    <!-- https://mvnrepository.com/artifact/net.sourceforge.jtds/jtds -->
    <!-- to connect to database -->
    <dependency>
        <groupId>net.sourceforge.jtds</groupId>
        <artifactId>jtds</artifactId>
        <version>1.2.4</version><!-- for java 6 -->
        <!-- <version>1.3.1</version> -->
    </dependency>

    <!-- for upload file -->
    <dependency>
        <groupId>commons-fileupload</groupId>
        <artifactId>commons-fileupload</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>1.4</version>
    </dependency>

    <!-- To read excel -->
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>3.10-FINAL</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.10-FINAL</version>
    </dependency>

    <!-- to map jodatime in JPA -->
    <dependency>
        <groupId>org.jadira.usertype</groupId>
        <artifactId>usertype.core</artifactId>
        <version>3.1.0.CR1</version>
    </dependency>

    <!-- custom jar -->
    <dependency>
        <groupId>com.aiahk.product</groupId>
        <artifactId>CommonUtil</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
</dependencies>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <start-class>web.Application</start-class>
    <java.version>1.6</java.version>

    <tomcat.version>7.0.52</tomcat.version>
</properties>

<build>
    <finalName>${artifactId}</finalName>
    <plugins>
        <!-- <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin> -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <useSystemClassLoader>false</useSystemClassLoader>
            </configuration>
        </plugin>
    </plugins>
</build>

这是我的application.properties

Here is my application.properties

    spring.mvc.view.prefix: /WEB-INF/jsp/
spring.mvc.view.suffix: .jsp


# Database
spring.datasource.driver-class-name=net.sourceforge.jtds.jdbc.Driver
spring.datasource.url=jdbc:jtds:sqlserver://{xxx}/{yyy}
spring.datasource.username=username
spring.datasource.password=password

# Keep the connection alive if idle for a long time (needed in production)
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1

# Show or not log for each sql query
spring.jpa.show-sql = false

# Hibernate ddl auto (create, create-drop, update, validate)
spring.jpa.hibernate.ddl-auto = update

# Naming strategy
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.EJB3NamingStrategy

# Use spring.jpa.properties.* for Hibernate native properties (the prefix is
# stripped before adding them to the entity manager)

# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.SQLServerDialect


com.ibm.websphere.persistence.ApplicationsExcludedFromJpaProcessing=*

Ps:我不了解spring boot项目与PLAYFRAMEWORK的关系.

Ps: I do not understand how spring boot project is related to PLAYFRAMEWORK.

推荐答案

Spring Boot 1.3.5带有嵌入式Hibernate JPA提供程序(版本4.3,该功能已经可以与JPA 2.1一起使用).

Spring Boot 1.3.5 comes with embedded Hibernate JPA provider (version 4.3, that is already capable to work with JPA 2.1).

不幸的是,WAS 8.0仅支持JPA 2.0,因此您必须更改persistence.xml,

Unfortunately, WAS 8.0 supports JPA 2.0 only, so you have to change persistence.xml, so instead

<persistence 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"
         version="2.1">
 ...
 </persistence>

尝试一下:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
    version="2.0">
...
</persistence>

此外,如果您打算使用Hibernate而不是嵌入式OpenJPA实现,则必须通过设置JVM属性 com.ibm.websphere.persistence.ApplicationsExcludedFromJpaProcessing = *

Also, if you intend to use Hibernate instead of embedded OpenJPA implementation, you have to turn OpenJPA off by setting JVM property com.ibm.websphere.persistence.ApplicationsExcludedFromJpaProcessing=*

不要忘记将类加载器策略设置为PARENT_LAST.

And don't forget to set classloader policy to PARENT_LAST.

此处部分覆盖了答案.

这篇关于Spring Boot Eclipse Maven WAS:创建名称为'entityManagerFactory'的bean时出错,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 13:18