Spring启动eclipse maven WAS:使用名称' entityManagerFactory',

时间:2016-10-26 08:22:14

标签: java jpa web spring-boot websphere

我正在尝试将我的网络应用程序部署到WAS8,但是我收到此错误消息。请帮忙!!

我的应用程序在命令运行时工作正常:" mvn spring-boot:run"。 我已经查看了许多与如何将弹簧启动项目部署到WAS8有关的网站,但我仍然无法完成这项工作..我不知道这里缺少什么。我是websphere的新手,我对websphere的配置知之甚少。请帮忙!!

[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

<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

    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:我不明白春季启动项目与PLAYFRAMEWORK的关系。

1 个答案:

答案 0 :(得分:2)

Spring Boot 1.3.5附带嵌入式Hibernate JPA提供程序(版本4.3,已经能够与JPA 2.1一起使用)。

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

<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=*来关闭OpenJPA

不要忘记将classloader策略设置为PARENT_LAST。

答案部分涵盖here