本文介绍了无法使用Spring Boot运行OpenJPA实体的静态增强的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

mvn package openjpa-maven-plugin:enhance 阶段失败在Spring Boot应用程序中增强我的JPA实体.

mvn package fails at the openjpa-maven-plugin:enhance stage when I try to enhance my JPA entities in a Spring Boot app.

错误说明很长

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

no configuration properties were found.

它列出了一些原因:

  • 我正在将spring-data-jpa与Java配置一起使用,并且没有
    persistence.xml. 是否可以在没有
    的情况下执行openjpa:enhance它吗?
    • I'm using spring-data-jpa with Java config, and there's no
      persistence.xml. Is it possible to do openjpa:enhance without
      it?
      • 我在Spring的 org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration -请参见下面的类. 这可能是我需要更改的,但是如何更改?在哪里指定属性文件以便openjpa-maven-plugin可以找到它?
        • I specify all the OpenJPA properties in a subclass of Spring's org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration - see the class below. This is probably what I need to change, but how? And where to specify the properties file so openjpa-maven-plugin can find it?
          • 已排除-我检查并使用checksumPolicy=fail重新下载了OpenJPA jar,以便证明它们没有损坏,而且我在该级别没有使用任何安全策略.
            • ruled out - I checked redownloaded the OpenJPA jars with checksumPolicy=fail so that's proof that they're not corrupted, plus I'm not using any security policy at this level.
            • 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-maven-plugin错误

              [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的子类

              Subclass of 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;
                  }
              
              
              }
              

              推荐答案

              这里的答案为我解决了.

              This answer here sorted it out for me.

              maven插件需要一个persistence.xml才能工作,这有点不干,因为我必须记住在其中列出任何新的实体bean,但我认为这是一个很小的价格.

              The maven plugin needs a persistence.xml to work, which is slightly not DRY because I have to remember to list any new entity beans in there, but I figured it's a small price.

              OpenJPA和Spring-boot配置

              这篇关于无法使用Spring Boot运行OpenJPA实体的静态增强的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 01:10