【问题标题】:Cannot run static enhancement of OpenJPA entities with Spring Boot无法使用 Spring Boot 运行 OpenJPA 实体的静态增强
【发布时间】:2017-04-30 23:18:30
【问题描述】:

当我尝试在 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 分发 jar 损坏,或者 如果您的安全政策过于严格。

    • 排除 - 我检查了使用 checksumPolicy=fail 重新下载的 OpenJPA jar,这证明它们没有损坏,而且我没有在此级别使用任何安全策略。

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


}

【问题讨论】:

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


    【解决方案1】:

    这里的答案为我解决了问题。

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

    OpenJPA and Spring-boot configuration

    【讨论】:

    • 面临同样的问题,您能否详细说明一下这个答案?
    • 您创建了persistence.xml 吗?这就是解决方案,即使除了 maven openjpa 插件之外没有任何必要。但这是3年前的事了。您是否检查过软件包的新版本?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-04
    • 2018-02-14
    • 1970-01-01
    • 2017-02-21
    • 2019-06-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多