2016-11-03 28 views
0

Intellij 2016とGradleを使用してアノテーション駆動のSpring MVCアプリケーションを作成しています。それをpersistence.xmlが見つかりません - NoSQLデータベースを使用したGradle-Spring-MVCプロジェクト

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 

:私は意図的にフォルダsrc/main/java/META-INF/persistence.xmlsrc/main/resources/META-INF/persistence.xmlpersistence.xmlをコピーしますが、Gradleの​​タスクを実行するときに、私は次のエラーを取得する

enter image description here

:私のプロジェクト構造は次のようになります​​タスクはクラスパスからpersistence.xmlを受け取ることができないようです。

誰もがそのエラーの背後にあることを知っていて、修正がありますか? javaguyため

EDIT、EntityManagerの行方不明のinit:アスタリスク忍者persistence.xmlを逃すための

/* 
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:

<?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、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") 
} 
+0

のためにいくつかの依存関係を追加しましたか?ロードするコードを表示しますか? – developer

+0

名前が示すように、 'src/main/java'はjavaファイル専用です。このフォルダには、xmlファイル(またはその他のJava以外のファイル)を置かないでください。リソースは 'src/main/resources'に入れてください。 –

+0

@Lance Java:わかりましたが、私は' persistence.xml'ファイルをspring-bootに送る方法を見つけようとしています。私はこれが醜いことを知っています。 – kiltek

答えて

1

私は解決の私アダプによる問題ティン、以下の方法で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.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") 
} 

その上のコメント:

  • persistence.xmlが正しく取り上げられたようですが、 EntitiyManager<provider>HibernateOgmPersistence正しく
を初期化できませんでした

したがって、次の変更が行われました:

  • はどのようにpersistence.xmlをロードしている MongoDBのインメモリ・インスタンスのための具体的なEntitiyManager
関連する問題