无法使用Spring Boot运行OpenJPA实体的静态增强

时间:2016-12-15 11:11:16

标签: maven spring-boot spring-data-jpa openjpa openjpa-maven-plugin

当我尝试在Spring Boot应用程序中增强JPA实体时,

mvn packageopenjpa-maven-plugin:enhance阶段失败。

有一个很长的错误描述

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分发包已损坏,也可能发生这种情况   如果你的安全政策过于严格。

    • 排除了 - 我使用checksumPolicy=fail检查了重新下载的OpenJPA广告集,以便证明他们没有损坏,另外我没有在此级别使用任何安全策略。< / LI>
  4. 的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

    的子类
    @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;
        }
    
    
    }
    

1 个答案:

答案 0 :(得分:0)

这个答案在这里为我排序。

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

OpenJPA and Spring-boot configuration