IgniteSpringBean&点燃SpringTransactionManager不再在2.4

时间:2018-05-25 04:10:27

标签: spring spring-boot spring-data ignite gridgain

我看到,在IgniteSpringBean中2.4中引入了一个更改以延迟点燃实例启动,直到所有其他spring bean被初始化可能已经破坏了Ignite SpringTransactionManager,导致无法为Ignite事务的Spring事务抽象配置它。我真的非常需要找到解决这个问题的方法。任何想法/建议任何人?

以下是来自IgniteSpringBean java doc的行 " Ignite实例在所有其他Spring bean初始化之后且在Spring上下文刷新之前启动。这意味着从任何类型的Spring bean初始化方法(如PostConstruct)引用IgniteSpringBean都无效。如果需要引用IgniteSpringBean用于其他bean初始化目的,则应该从该bean中声明的ContextRefreshedEvent侦听器方法完成。 "

问题,因为SpringTransactionManager实现了org.springframework.beans.factory.InitializingBean&春天调用的afterPropertiesSet()调用中的试图查找指定的igniteInstanceName,但由于实例仅在启动后所有其他Spring bean都已初始化,失败使用IgniteIllegalStateException

请参阅下面的堆栈跟踪,

lass]:调用init方法失败;嵌套异常是类org.apache.ignite.IgniteIllegalStateException:提供名称的Ignite实例不存在。你有没有调用Ignition.start(..)来启动一个Ignite实例? [名称= ObjectManagerGrid]     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)     at org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:306)     在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)     在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)     在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)     在org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)     在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)     at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)     在org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737)     在org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370)     在org.springframework.boot.SpringApplication.run(SpringApplication.java:314)     在com.brocade.dcm.Application.main(Application.java:63)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:498)     在org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)     在org.springframework.boot.loader.Launcher.launch(Launcher.java:87)     在org.springframework.boot.loader.Launcher.launch(Launcher.java:50)     在org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) 引起:org.apache.ignite.IgniteIllegalStateException:提供名称的Ignite实例不存在。你有没有调用Ignition.start(..)来启动一个Ignite实例? [名称= ObjectManagerGrid]     在org.apache.ignite.internal.IgnitionEx.grid(IgnitionEx.java:1376)     在org.apache.ignite.Ignition.ignite(Ignition.java:530)     在org.apache.ignite.transactions.spring.SpringTransactionManager.afterPropertiesSet(SpringTransactionManager.java:357)     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)     ...省略了22个常见帧

由于

1 个答案:

答案 0 :(得分:0)

对于其他面临此问题的人,如Dennis(@dmagda)所评论,此票证已https://issues.apache.org/jira/browse/IGNITE-8740已修复,并且将在2.6中可用。

与此同时,我要做的是通过这种方式在配置bean(@Configuration)中修改注入,

/**
 * @author mlekshma
 *
 */
@Configuration
@ComponentScan("com.***.***")
@EnableIgniteRepositories(basePackages={"com.***.***"})
@ImportResource("classpath:ignite-client-conf.xml")
@EnableTransactionManagement
public class IgniteClientConfig {

    private static final Logger LOGGER = LoggerFactory.getLogger(IgniteClientConfig.class);

    public IgniteClientConfig() {
    }

    /**
     * @return
     */
    @Bean
    @DependsOn("igniteInstance")
    @Primary
    @Lazy
    public PlatformTransactionManager transactionManager() {
        final SpringTransactionManager springTransactionManager = new SpringTransactionManager() {
            @Override 
            public void afterPropertiesSet() throws Exception {
                // Do nothing..
            }

            /**
             * @param event
             */
            @EventListener
            public void handleContextRefresh(final ContextRefreshedEvent event) throws Exception {
                LOGGER.info("Setting up tx support..");
                super.afterPropertiesSet();
            }
        };
        // Use default grid client instance created..
        springTransactionManager.setTransactionConcurrency(TransactionConcurrency.PESSIMISTIC);
        return springTransactionManager;
    }

}