gpt4 book ai didi

java - Spring启动eclipse maven WAS : Error creating bean with name 'entityManagerFactory' ,

转载 作者:行者123 更新时间:2023-11-30 02:45:43 24 4
gpt4 key购买 nike

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

我的应用程序在命令“mvn spring-boot:run”上运行时工作正常。我已经检查了许多与如何将 Spring Boot 项目部署到 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:我不明白spring boot项目与PLAYFRAMEWORK有什么关系。

最佳答案

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

并且不要忘记将类加载器策略设置为 PARENT_LAST。

答案已被部分覆盖 here .

关于java - Spring启动eclipse maven WAS : Error creating bean with name 'entityManagerFactory' ,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40257154/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com