更新时间:2023-11-17 23:30:58
我通过以如下方式调整 build.gradle
文件来解决我的问题:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath(org.springframework.boot:spring-boot- gradle-plugin:1.4.1.RELEASE)
}
}
apply plugin:'java'
apply plugin:'idea'
apply插件:'spring-boot'
jar {
baseName ='gs-serving-web-content'
version ='0.1.0'
}
存储库{
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
依赖关系{
compile(org.springframework.boot:spring-boot-starter-thymeleaf)
compile(org.springframework.boot:spring-boot-devtools)
compile(org.hibernate.ogm:hibernate-ogm-bom:5.0.2.Final)
compile group :'org.hibernate.ogm',名称:'hibernate-ogm-infinispan',版本:'5.0.2.Final'
编译组:'org.jboss.spec.javax.transaction',名称:' jboss-transaction-api_1.2_spec',版本:'1.0.0.Final'
编译组:'org.hibernate.javax.persistence',名称:'hibernate-jpa-2.1-api',版本:' 1.0.0.Final'
编译组:'org.jboss.narayana.jta',名称:'narayana-jta',版本:'5.3.5.Final'
编译组:'org。 'jboss',名称:'jboss-transaction-spi',版本:'7.5.0.Final'
编译组:'javax.transaction',名称:'jta',版本:'1.1'
编组:'org .hibernate.common',name:'hibernate-commons-annotations',version:'5.0.1.Final'
testCompile(junit:junit)
}
对此的评论:
persistence.xml
被正确拾取,但 EntitiyManager
无法初始化< provider> HibernateOgmPersistence
正确
因此进行了以下更改: / b>
EntitiyManager
的一些依赖关系,内存实例I am creating an annotation driven Spring MVC application using Intellij 2016 and Gradle. My project structure looks like this:
I deliberately copied the persistence.xml
into the folder src/main/java/META-INF/persistence.xml
and src/main/resources/META-INF/persistence.xml
, but when executing the Gradle bootRun
task, I get the following error:
11:18:40: Executing external task 'bootRun'...
:compileJava
:processResources
:classes
:findMainClass
:bootRun
11:18:52.960 [main] DEBUG org.jboss.logging - Logging Provider: org.jboss.logging.Slf4jLoggerProvider
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named ogm-jpa-tutorial
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
at my.app.main.Application.main(Application.java:27)
:bootRun FAILED
It seems that the bootRun
tasks is not able to pick up the persistence.xml
from the classpath.
Does anyone know whats behind that error and has a fix?
EDIT for javaguy, missing init of EntityManager
:
/*
Content of the class my.app.main.Application
*/
package my.app.main;
import my.app.controllers.GreetingController;
import my.app.model.Greeting;
import org.hibernate.validator.internal.util.logging.Log;
import org.hibernate.validator.internal.util.logging.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.transaction.TransactionManager;
@SpringBootApplication
@ComponentScan({"my.app.*"})
public class Application {
private static final Log logger = LoggerFactory.make();
public static void main(String[] args) {
TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
EntityManagerFactory emf = Persistence.createEntityManagerFactory("ogm-jpa-tutorial");
SpringApplication.run(Application.class, args);
}
}
EDIT for Asterisk Ninja missing persistence.xml
:
<?xml version="1.0"?>
<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-unit name="ogm-jpa-tutorial" transaction-type="JTA">
<!-- Use the Hibernate OGM provider: configuration will be transparent -->
<provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
<properties>
<!-- Here you will pick which NoSQL technology to use, and configure it;
in this example we start a local in-memory Infinispan node. -->
<property name="hibernate.ogm.datastore.provider" value="infinispan"/>
</properties>
</persistence-unit>
</persistence>
EDIT, missing build.gradle
:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.1.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'gs-serving-web-content'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-devtools")
compile("org.hibernate.ogm:hibernate-ogm-bom:5.0.2.Final")
compile group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.1-api', version: '1.0.0.Final'
compile group: 'javax.transaction', name: 'jta', version: '1.1'
compile group: 'org.jboss.narayana.jta', name: 'narayana-jta', version: '5.3.5.Final'
compile group: 'org.hibernate', name: 'hibernate-annotations', version: '3.5.6-Final'
testCompile("junit:junit")
}
I solved my problem by adapting the build.gradle
file in the following fashion:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.1.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'gs-serving-web-content'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-devtools")
compile("org.hibernate.ogm:hibernate-ogm-bom:5.0.2.Final")
compile group: 'org.hibernate.ogm', name: 'hibernate-ogm-infinispan', version: '5.0.2.Final'
compile group: 'org.jboss.spec.javax.transaction', name: 'jboss-transaction-api_1.2_spec', version: '1.0.0.Final'
compile group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.1-api', version: '1.0.0.Final'
compile group: 'org.jboss.narayana.jta', name: 'narayana-jta', version: '5.3.5.Final'
compile group: 'org.jboss', name: 'jboss-transaction-spi', version: '7.5.0.Final'
compile group: 'javax.transaction', name: 'jta', version: '1.1'
compile group: 'org.hibernate.common', name: 'hibernate-commons-annotations', version: '5.0.1.Final'
testCompile("junit:junit")
}
Comment on that:
persistence.xml
was picked up correctly, but the
EntitiyManager
could not initialize the <provider>HibernateOgmPersistence
correctly therefore the following changes were done:
EntitiyManager
specific for the
MongoDB in-memory instance