2016-10-19 12 views
3

OpenJPAをjpa実装としてSpringブートアプリケーションの基本構成に苦しんでいます。基本的に私はいつも以下のように終わります。OpenJPAとSpringブート構成

原因:org.apache.openjpa.util.MetaDataException:タイプ "class com.openjpa.example.Customer"が拡張されていません。

私の構成は以下のようになります。

package com.openjpa.example; 

    @SpringBootApplication 
    public class Application extends JpaBaseConfiguration { 
     protected Application(DataSource dataSource, JpaProperties properties, 
       ObjectProvider<JtaTransactionManager> jtaTransactionManagerProvider) { 
      super(dataSource, properties, jtaTransactionManagerProvider); 
     } 

     @Override 
     protected AbstractJpaVendorAdapter createJpaVendorAdapter() { 
      OpenJpaVendorAdapter jpaVendorAdapter = new OpenJpaVendorAdapter(); 
      jpaVendorAdapter.setShowSql(true); 
      return jpaVendorAdapter; 
     } 

     @Override 
     protected Map<String, Object> getVendorProperties() { 
      HashMap<String, Object> map = new HashMap<String, Object>(); 
      map.put("openjpa.Log", "DefaultLevel=TRACE, Tool=INFO, SQL=TRACE, Runtime=TRACE"); 
      map.put("openjpa.jdbc.MappingDefaults", "IndexLogicalForeignKeys=false,IndexDiscriminator=false"); 
      map.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)"); 
      map.put("openjpa.RuntimeUnenhancedClasses", "supported"); 
      map.put("openjpa.DynamicEnhancementAgent", "false"); 
      map.put("openjpa.weaving", "false"); 
      return map; 
     } 

     public static void main(String[] args) { 
      CustomerRepository repository = SpringApplication.run(Application.class, args).getBean(CustomerRepository.class); 
      repository.save(new Customer("Richard", "Feynman")); 


      System.out.println(repository.findAll()); 
     } 
    } 

とのpom.xml:

<profiles> 
    <profile> 
     <id>static-weaving</id> 

      <build> 
       <plugins> 

       <plugin> 
       <groupId>org.apache.openjpa</groupId> 
       <artifactId>openjpa-maven-plugin</artifactId> 
       <configuration> 
        <includes>**/openjpa/*.class</includes> 
        <addDefaultConstructor>true</addDefaultConstructor> 
        <enforcePropertyRestrictions>true</enforcePropertyRestrictions> 

       </configuration> 
       <executions> 
        <execution> 
         <id>enhancer</id> 
         <phase>process-classes</phase> 
         <goals> 
          <goal>enhance</goal> 
         </goals> 
        </execution> 
       </executions> 
       <dependencies> 
        <dependency> 
         <groupId>org.apache.openjpa</groupId> 
         <artifactId>openjpa</artifactId> 
         <version>${openjpa.version}</version> 
        </dependency> 
       </dependencies> 
      </plugin> 
       </plugins> 
      </build> 

     </profile> 

     <profile> 

      <id>load-time-weaving</id> 

      <activation> 
       <activeByDefault>true</activeByDefault> 
      </activation> 

      <build> 
       <plugins> 
        <plugin> 
         <groupId>org.apache.maven.plugins</groupId> 
         <artifactId>maven-surefire-plugin</artifactId> 
         <dependencies> 
          <dependency> 
           <groupId>org.springframework</groupId> 
           <artifactId>spring-instrument</artifactId> 
           <version>${spring.version}</version> 
          </dependency> 
         </dependencies> 
         <configuration> 
          <argLine>-javaagent:${settings.localRepository}/org/springframework/spring-instrument/${spring.version}/spring-instrument-${spring.version}.jar</argLine> 
         </configuration> 
        </plugin> 
        <plugin> 

         <groupId>org.springframework.boot</groupId> 
         <artifactId>spring-boot-maven-plugin</artifactId> 
         <dependencies> 
          <dependency> 
           <groupId>org.springframework</groupId> 
           <artifactId>spring-instrument</artifactId> 
           <version>${spring.version}</version> 
          </dependency> 
         </dependencies> 
         <configuration> 
          <agent>${settings.localRepository}/org/springframework/spring-instrument/${spring.version}/spring-instrument-${spring.version}.jar</agent> 
          <agent>${settings.localRepository}/org/apache/openjpa/openjpa/${openjpa.version}/openjpa-${openjpa.version}.jar</agent> 
         </configuration> 
        </plugin> 
       </plugins> 
      </build> 
    </profile> 

</profiles> 

誰もがここで間違っているものを知っていますか?

+0

-all-2.4.1.jar " – nbaplaya

+0

静的な拡張機能を利用できましたか?私は質問を投稿しました:http://stackoverflow.com/questions/41162726/cannot-run-static-enhancement-of-openjpa-entities-with-spring-boot – Adam

+0

「openjpa」に関するドキュメントも見つかりません。織り成す "特性 - これは以前のバージョンの遺物ですか? – Adam

答えて

0

ここには、ビルド時にエンティティクラスを強化するためのエントリがあります。それは私のために働いた。 また、ビルド時にクラスを強化するためにはMETA-INF/persistence.xmlが必要であり、実行時には不要であることに注意してください。したがって、jarの作成中にpersistence.xmlを除外できます。 -javaagent::。 "$ {のuser.home}/2 /リポジトリ/組織/ apacheの/ OpenJPAの/ OpenJPAの-すべて/ 2.4.1/OpenJPAのを解決し、私の問題は以下のようにVM引数を追加

<pluginManagement> 
     <plugins> 
      <plugin> 
       <groupId>org.eclipse.m2e</groupId> 
       <artifactId>lifecycle-mapping</artifactId> 
       <version>1.0.0</version> 
       <configuration> 
        <lifecycleMappingMetadata> 
         <pluginExecutions> 
          <pluginExecution> 
           <pluginExecutionFilter> 
            <groupId>org.apache.openjpa</groupId> 
            <artifactId>openjpa-maven-plugin</artifactId> 
            <versionRange>2.2.0</versionRange> 
            <goals> 
             <goal>enhance</goal> 
            </goals> 
           </pluginExecutionFilter> 
           <action> 
            <execute /> 
           </action> 
          </pluginExecution> 
         </pluginExecutions> 
        </lifecycleMappingMetadata> 
        <includes>**/domain/*.class</includes> 
        <addDefaultConstructor>true</addDefaultConstructor> 
        <enforcePropertyRestrictions>true</enforcePropertyRestrictions> 
       </configuration> 
      </plugin> 
     </plugins> 
    </pluginManagement> 

    <plugins> 
     ..... 
     <plugin> 
      <groupId>org.apache.openjpa</groupId> 
      <artifactId>openjpa-maven-plugin</artifactId> 
      <version>2.2.0</version> 
      <configuration> 
       <includes>**/domain/*.class</includes> 
       <addDefaultConstructor>true</addDefaultConstructor> 
       <enforcePropertyRestrictions>true</enforcePropertyRestrictions> 
       <persistenceXmlFile>${project.basedir}/src/main/resources/META-INF/persistence.xml</persistenceXmlFile> 
      </configuration> 
      <executions> 
       <execution> 
        <id>enhancer</id> 
        <phase>process-classes</phase> 
        <goals> 
         <goal>enhance</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 

    </plugins> 

</build> 
関連する問題