mvn package
openjpa-maven-plugin:enhance
在我尝试在 Spring Boot 应用程序中增强我的 JPA 实体时失败。
错误描述很长
enhance failed: MetaDataFactory could not be configured (conf.newMetaDataFactoryInstance() returned null).
no configuration properties were found.
它列出了一些原因:
确保你有一个 META-INF/persistence.xml 文件,它在你的类路径中可用
- 我正在使用
spring-data-jpa
Java 配置,但没有
persistence.xml
. 没有它有可能 吗?openjpa:enhance
- 我正在使用
确保您用于配置的属性文件可用。如果您使用的是 Ant,请查看任务嵌套元素的 或 属性。
- 我在 Spring 的子类中指定了所有 OpenJPA 属性
org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration
- 请参见下面的类。这可能是我需要改变的,但是如何改变?以及在哪里指定属性文件以便openjpa-maven-plugin
可以找到它?
- 我在 Spring 的子类中指定了所有 OpenJPA 属性
如果您的 OpenJPA 分发 jar 损坏,或者您的安全策略过于严格,也会发生这种情况。
- 排除 - 我检查了重新下载的 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;
}
}