2017-04-09 6 views
1
@Configuration 
@EnableTransactionManagement 
public class DataSourceConfig { 

    @Bean(destroyMethod = "shutdown") 
    public DataSource dataSource(){ 
     EmbeddedDatabaseBuilder databaseBuilder = new EmbeddedDatabaseBuilder(); 
     databaseBuilder.setType(EmbeddedDatabaseType.H2); 
     databaseBuilder.addScript("classpath:db/migration/V1__Create_Books_Table.sql"); 
     databaseBuilder.addScript("classpath:db/migration/V2__Add_Books.sql"); 
     return databaseBuilder.build(); 
    } 

    @Bean 
    public JpaVendorAdapter vendorAdapter(){ 

     HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); 
     vendorAdapter.setGenerateDdl(true); 
     vendorAdapter.setDatabase(Database.H2); 
     vendorAdapter.setShowSql(true); 
     vendorAdapter.setDatabasePlatform("org.hibernate.dialect.H2Dialect"); 
     return vendorAdapter; 
    } 

    @Bean(name = "entityManagerFactory") 
    public EntityManagerFactory managerFactory(){ 
    Properties jpaProperties = new Properties(); 
    jpaProperties.put("hibernate.hbm2ddl.auto", "create-drop"); 

    LocalContainerEntityManagerFactoryBean managerFactoryBean = new LocalContainerEntityManagerFactoryBean(); 
    managerFactoryBean.setDataSource(dataSource()); 
    managerFactoryBean.setJpaVendorAdapter(vendorAdapter()); 
    managerFactoryBean.setPackagesToScan("com.sammy"); 
    managerFactoryBean.setJpaProperties(jpaProperties); 
    managerFactoryBean.afterPropertiesSet(); 
    return managerFactoryBean.getObject(); 
} 

    @Bean 
    public PlatformTransactionManager transactionManager(){ 
     JpaTransactionManager transactionManager = new JpaTransactionManager(); 
     transactionManager.setEntityManagerFactory(managerFactory()); 
     return transactionManager; 
    } 
} 

私のコンフィギュレーションクラスであり、私のGradleのビルドファイルがjava.lang.NoSuchMethodErrorの:org.hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava/utilに/プロパティ

buildscript { 

    repositories { 
     jcenter() 
     maven { 
      url "https://plugins.gradle.org/m2/" 
     } 
    } 
    dependencies { 
     classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:${sonarVersion}" 
     classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}" 
    } 
} 

apply plugin: 'java' 
apply plugin: 'jacoco' 
apply plugin: 'org.sonarqube' 
apply plugin: 'org.springframework.boot' 

sourceCompatibility = 1.8 
targetCompatibility = 1.8 

repositories { 
    mavenCentral() 
} 

jar{ 
    group 'com.sammy' 
    version '1.0-SNAPSHOT' 
} 

dependencies { 

    testCompile "junit:junit:${junitVersion}" 
    testCompile "info.cukes:cucumber-java:${cucumberVersion}" 
    testCompile "info.cukes:cucumber-junit:${cucumberVersion}" 
    //testCompile "info.cukes:cucumber-spring:${cucumberVersion}" 
    testCompile 'org.springframework.boot:spring-boot-starter-test' 

    compile 'com.h2database:h2' 
    compile "org.flywaydb:flyway-core:${flywayVersion}" 
    compile "org.projectlombok:lombok:${lombokVersion}" 
    compile("org.springframework.boot:spring-boot-starter-web") { 
     exclude module: "spring-boot-starter-tomcat" 
    } 

    compile "org.hibernate:hibernate-core:${hibernateVersion}" 
    compile 'org.springframework.boot:spring-boot-starter-aop' 
    compile 'org.springframework.boot:spring-boot-starter-jetty' 
    compile "io.springfox:springfox-swagger2:${swaggerVersion}" 
    compile "org.jadira.usertype:usertype.core:${jadiraVersion}" 
    compile "io.springfox:springfox-swagger-ui:${swaggerVersion}" 
    compile 'org.springframework.boot:spring-boot-starter-actuator' 
    compile 'org.springframework.cloud:spring-cloud-starter-config' 
    compile 'org.springframework.boot:spring-boot-starter-data-jpa' 
    //compile 'org.springframework.boot:spring-boot-starter-data-mongodb' 
} 

task wrapper(type :Wrapper){ 
    gradleVersion = '3.4.1' 
} 

私の一方であります

:Gradleのプロパティファイルが

junitVersion = 4.12 
sonarVersion = 2.2.1 
flywayVersion = 4.1.2 
swaggerVersion = 2.6.1 
cucumberVersion = 1.2.5 
lombokVersion = 1.16.14 
jadiraVersion = 6.0.1.GA 
hibernateVersion = 5.2.9.Final 
springBootVersion = 1.5.2.RELEASE 

この問題は、私はこれはまだ、このエラーメッセージをスローせずに動作しません、私のエンティティクラスでJava 8のLOCALDATEを使用したいが、あるあります

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [com/sammy/config/DataSourceConfig.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava/util/Properties; 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:856) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE] 
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE] 
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE] 
    at com.sammy.SpringDataTutorials.main(SpringDataTutorials.java:18) [main/:na] 
Caused by: java.lang.NoSuchMethodError: org.hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava/util/Properties; 
    at org.hibernate.jpa.internal.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:124) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final] 
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:890) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final] 
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) ~[spring-orm-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353) ~[spring-orm-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:370) ~[spring-orm-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:359) ~[spring-orm-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    ... 16 common frames omitted 

jadiraコアまたはspiライブラリをgradleビルドファイルに追加するかどうかは、同じエラーが表示されます。 SpringBootはstacktraceにspring-orm-4.3.7.RELEASEをそのまま使用し、その後、Hibernateコアバージョン5.2.9を追加します.FINALはそれをそのバージョンにアップグレードします。私はここで言及されたほとんどすべての異なる問題を見てきましたが、このバージョンでは何も扱っていません。私はまた、それがうまくいっているはずだと言っている冬眠の最新バージョンのドキュメントを読んだことがありますが、それは私にとってはなぜそうは分かりません。

INFO 26648 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found。私はJpaTransactionManagerを、注入されたentityManagerFactoryを使用するように変更しましたが、これらの回答の1つが示唆されていましたが、gradleとintellijを使ってプロジェクトを再構築してもまだ動作しませんでした。私はHibernate 5.2.9.FINALドキュメントを見て、そのメソッドgetProperties()は存在しなくなりましたが、entitiyManagerFactoryから継承されました。また、ほとんどの回答は、Javaの設定ではなく、xmlの設定で行われましたが、プロパティを使用するのではなく、Javaの設定状況でマップに変更する方法についての説明はありません。 hibiernatesバージョンを5.1.xにドロップすると、そのエラーメッセージが表示されますが、Java 8 LocalDateタイプのエラーメッセージが表示されます。これは、そのバージョンのHibernateにJavaの機能がサポートされていないためです。

+0

[JUnitの4とSpringデータJPA有するばね試験:NoSuchMethodError org.hibernate.engine.spi.SessionFactoryImplementor.getProperties]の可能な重複(http://stackoverflow.com/questions/39815784/spring-test- –

+0

これは、それぞれの潜在的な解決策が異なる他の問題を思いついているので、最終的に問題を解決するためには非常に多くのステップを必要としました。私は、私が遭遇した他の問題を解決するための措置とリンクを与え、誰かを助ける可能性があります。リンクは間違いなく正しい方向に私を設定しました。 – Sammy65

答えて

0

Neilのリンクに基づいて、setJpaPropertyMap()を作成して使用してプロパティマップを設定する方法を見つけることができました。そして、それは私が解決するために

@Bean 
    public InstrumentationLoadTimeWeaver loadTimeWeaver() throws Exception { 
     InstrumentationLoadTimeWeaver loadTimeWeaver = new InstrumentationLoadTimeWeaver(); 
     return loadTimeWeaver; 
    } 

を使用LoadTimeWeaversとは異なるエラーを与えました。そして、これは私がそれを解決するためにGradleのプロジェクトだから、このリンクhttp://gradle.1045684.n5.nabble.com/Java-Agent-LTW-problem-with-Gradle-and-Jetty-td4938600.htmlを使用し、ちょうど現在の春の計装バージョンにバージョンを変更した

java.lang.IllegalStateException: Must start with Java agent to use InstrumentationLoadTimeWeaver. See Spring documentation. 

のエラーメッセージを与えました。この問題を解決するために必要なすべてのステップを踏まえれば、これは重複していないことがわかります。

1

どのバージョンのGradleをお持ちですか?

私は3.5から4.3までアップグレードGradle後に発生する同じエラーがあるので、私は尋ねます。同じHibernateバージョン(5.2.9)、同じSpring Boot(1.5.8)がGradle 3.5にあります。 - OK、4.3が失敗します。

私はテストして、最新のバージョンは問題なく動作していました。3.5.1。 4.0から4.4-rc-6までのバージョンをテストしました(この時点で最新です)。

distributionUrl=https\://services.gradle.org/distributions/gradle-3.5.1-all.zip 
+0

こんにちは!当時のグラデル版は3.4.1と私の質問にあります。私は4.4 gradleバージョンを使用するようにそのプロジェクトを更新し、すべての作品がうまくいきます。これは遅い回答かもしれません:-) – Sammy65

+0

5月12日4.3 gradle - 私は私のプロジェクト4.4バージョンをチェックします:) –

関連する問題