簡體   English   中英

如何啟用 eclipselink static 與 gradle 一起編織在 spring 引導中

[英]How to enable the eclipselink static weaving in spring boot along with gradle

  1. 涉及https://plugins.gradle.org/plugin/org.jamgo.eclipselink-plugin
  2. 檢查日志 [EL 警告]:元數據:ServerSession(1559673372)--恢復實體 class [類 com.hybris.caas.order.model.Order] 的 OneToOne 或 ManyToOne 屬性 [copyCustomer] 的惰性設置,因為編織是未啟用或未發生。
   @Configuration
public class JpaConfig extends JpaBaseConfiguration {

   protected JpaConfig(DataSource dataSource, JpaProperties properties,
                       ObjectProvider<JtaTransactionManager> jtaTransactionManagerProvider,
                       ObjectProvider<TransactionManagerCustomizers> transactionManagerCustomizers) {
       super(dataSource, properties, jtaTransactionManagerProvider, transactionManagerCustomizers);
   }

   @Override
   protected AbstractJpaVendorAdapter createJpaVendorAdapter() {
       return new EclipseLinkJpaVendorAdapter();
   }

   @Override
   protected Map<String, Object> getVendorProperties() {
       final HashMap<String, Object> props = new HashMap<>();
       props.put(PersistenceUnitProperties.WEAVING, detectWeavingMode());
       return props;
   }

   private String detectWeavingMode() {
       return "static";
   }

   /**
    *
    * @param entityManagerFactory
    * @return
    */
   @Bean
   public PlatformTransactionManager transactionManager(final EntityManagerFactory entityManagerFactory) {
       final JpaTransactionManager transactionManager = new JpaTransactionManager();
       transactionManager.setEntityManagerFactory(entityManagerFactory);
       return transactionManager;
   }

}
buildscript {
  repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }
  dependencies {
    classpath "gradle.plugin.org.jamgo:eclipselink-plugin:0.2.2"
  }
}

apply plugin: "org.jamgo.eclipselink-plugin"

我不確定這個插件及其功能,但是如果沒有插件,純 Gradle 是可能的。

要完成這項工作,需要執行 3 個步驟:

  • 將 persistence.xml 文件復制到類旁邊的源文件夾中
  • 做編織
  • 從類源文件夾中刪除persistence.xml文件,以避免類路徑上重復的persistence.xml沖突

此外,將流程連接到 compileJava 任務的最后一步非常重要,以免破壞 Gradle 的最新檢查。

更詳細的解釋可以看我在上面的文章: EclipseLink static weaving with Gradle

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM