0

mvn package在我試圖在Spring Boot應用程序中增強JPA實體時在openjpa-maven-plugin:enhance階段失敗。無法使用Spring Boot運行OpenJPA實體的靜態增強

還有很長的錯誤描述

enhance failed: MetaDataFactory could not be configured (conf.newMetaDataFactoryInstance() returned null).

no configuration properties were found.

它列出了一些原因:

  1. 確保您有一個META-INF/persistence.xml文件,它是 可用在您的類路徑

    • 我使用spring-data-jpa與Java的配置,而且也沒有
      persistence.xml可以做openjpa:enhance沒有
      嗎?
  2. 確保屬性文件你正在使用的配置 可用。如果您正在使用Ant,請參閱任務嵌套元素的或 屬性。

  3. 這也可能發生,如果你的OpenJPA的分配罐已損壞,或 。

    • 排除了 - 我查了重新下載OpenJPA的罐子checksumPolicy=fail所以這是證明他們沒有損壞,再加上我沒有使用任何安全策略在這個水平。

的pom.xml

 <plugin> 
      <groupId>org.apache.openjpa</groupId> 
      <artifactId>openjpa-maven-plugin</artifactId> 
      <configuration> 
       <includes>**/entity/*.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> 
     </plugin> 

OpenJPA的-行家-插件錯誤

[INFO] --- openjpa-maven-plugin:2.4.1:enhance (enhancer) @ project-x --- 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 16.707 s 
[INFO] Finished at: 2016-12-15T09:51:36+00:00 
[INFO] Final Memory: 44M/359M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.apache.openjpa:openjpa-maven-plugin:2.4.1:enhance 
(enhancer) on project x: Execution enhancer of goal org.apache.openjpa:openjpa-maven-plugin:2.4.1:enhance 
failed: MetaDataFactory could not be configured (conf.newMetaDataFactoryInstance() 
returned null). This might mean that no configuration properties were found. Ensure that 
you have a META-INF/persistence.xml file, that it is available in your classpath, or that 
the properties file you are using for configuration is available. If you are using Ant, 
please see the <properties> or <propertiesFile> attributes of the task's nested <config> 
element. This can also occur if your OpenJPA distribution jars are corrupt, or if your 
security policy is overly strict. -> [Help 1] 

子類的JpaBaseConfiguration

@Import({ 
     LdapConfig.class, 
     SecurityConfig.class, 
     PropertySpringConfig.class 
}) 
@SpringBootApplication 
@EnableJpaRepositories(basePackages = {"com.adam.x.repository"}) 
@EntityScan(basePackages = {"com.adam.x.entity"}) 
public class MyWebApplication extends JpaBaseConfiguration { 

    public static void main(String[] args) { 
     SpringApplication.run(MyWebApplication.class, args); 
    } 

    protected MyWebApplication(
      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", "true"); 
//  map.put("openjpa.weaving", "false"); 
     return map; 
    } 


} 

回答

0

這個答案在這裏整理出來給我。

maven插件需要persistence.xml才能工作,這有點不幹,因爲我必須記住列出所有新的實體bean,但我認爲這是一個小的代價。

OpenJPA and Spring-boot configuration