2017-01-17 9 views
1

動作しないのはなぜ、私はそれはJPA-TXを返す---私@Configurationクラスで、私はインターフェイスTransactionManagementConfigurerとオーバーライドメソッドannotationDrivenTransactionManagerを実装して、defaultのTransactionManagerを定義したいと思います。しかし、私は私のアプリを起動したとき、私は混乱しましたエラー:JPA + TransactionManagementConfigurerがSpring4にJPAで

2017-02-14 15:00:19.108 [localhost-startStop-1] ERROR org.springframework.web.context.ContextLoader - Context initialization failed 
java.lang.NoClassDefFoundError: org.springframework.beans.FatalBeanException 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) ~[spring-beans-4.2.8.RELEASE.jar:4.2.8.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.8.RELEASE.jar:4.2.8.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.8.RELEASE.jar:4.2.8.RELEASE] 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.8.RELEASE.jar:4.2.8.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.8.RELEASE.jar:4.2.8.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.8.RELEASE.jar:4.2.8.RELEASE] 
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:368) ~[spring-beans-4.2.8.RELEASE.jar:4.2.8.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1127) ~[spring-beans-4.2.8.RELEASE.jar:4.2.8.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1022) ~[spring-beans-4.2.8.RELEASE.jar:4.2.8.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[spring-beans-4.2.8.RELEASE.jar:4.2.8.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.8.RELEASE.jar:4.2.8.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.8.RELEASE.jar:4.2.8.RELEASE] 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.8.RELEASE.jar:4.2.8.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.8.RELEASE.jar:4.2.8.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.8.RELEASE.jar:4.2.8.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1054) ~[spring-context-4.2.8.RELEASE.jar:4.2.8.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:829) ~[spring-context-4.2.8.RELEASE.jar:4.2.8.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) ~[spring-context-4.2.8.RELEASE.jar:4.2.8.RELEASE] 
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444) ~[spring-web-4.2.8.RELEASE.jar:4.2.8.RELEASE] 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326) [spring-web-4.2.8.RELEASE.jar:4.2.8.RELEASE] 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107) [spring-web-4.2.8.RELEASE.jar:4.2.8.RELEASE] 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4937) [tomcat-embed-core-7.0.47.jar:7.0.47] 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434) [tomcat-embed-core-7.0.47.jar:7.0.47] 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [tomcat-embed-core-7.0.47.jar:7.0.47] 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) [tomcat-embed-core-7.0.47.jar:7.0.47] 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) [tomcat-embed-core-7.0.47.jar:7.0.47] 
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_45] 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_45] 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_45] 
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_45] 

java.lang.NoClassDefFoundError: org.springframework.beans.FatalBeanExceptionは何を意味します。

これは、Configクラスである:

@Configuration 
@EnableJpaRepositories(basePackages = {"cn.madmind.config"}) 
@EnableTransactionManagement 
@ComponentScan(basePackages = {"cn.madmind.config"}) 
public class RootApplicationConfig implements TransactionManagementConfigurer { 

    @Bean 
    public DataSource dataSource() { 
     DriverManagerDataSource datasource = new DriverManagerDataSource(); 
     datasource.setDriverClassName("com.mysql.jdbc.Driver"); 
     datasource.setUrl("jdbc:mysql://localhost:3306/alioth"); 
     datasource.setUsername("root"); 
     datasource.setPassword(""); 
     return datasource; 
    } 

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

    @Bean 
    public LocalContainerEntityManagerFactoryBean entityManagerFactory() { 
     LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean(); 
     HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter(); 
     adapter.setDatabasePlatform("org.hibernate.dialect.MySQL5InnoDBDialect"); 
     factory.setJpaVendorAdapter(adapter); 
     factory.setDataSource(dataSource()); 
     factory.setPackagesToScan("cn.madmind.config"); 
     return factory; 
    } 

    /** 
    * set default transaction-manager 
    */ 
    @Override 
    public PlatformTransactionManager annotationDrivenTransactionManager() { 
     return transactionManager(); 
    } 
} 

答えて

0

それはそれはSpringフレームワーク自体のバグだ可能です:https://jira.spring.io/browse/SPR-10787

私は理論的だフレームワークのバージョンでは、しかし、現在、同様の問題に直面しています固定されている(4.1.9.RELEASEと4.3.9.RELEASE)ので、あなたの人件費は異なるかもしれません。

編集:私たちのプロジェクトは、春の古いバージョンのために飛んだが、未遂アップグレード中に壊れた@Imported @Configuration、(いくつかの誤っ静的ビーンファクトリメソッド、 と直接autowiredフィールド)の周りにいくつかの疑問オートワイヤリングを持っていたようです。

問題を少しでも分けて、ドキュメントのような設定ファイルのコンストラクタインジェクションを行っていることを確認すると、http://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/context/annotation/Configuration.htmlが私のために修正されました。