IgniteSpringBean &Ignite SpringTransactionManager 在 2.4 中不再协同工作 [英] IgniteSpringBean & Ignite SpringTransactionManager do not work together anymore in 2.4

查看:24
本文介绍了IgniteSpringBean &Ignite SpringTransactionManager 在 2.4 中不再协同工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I see that with a change introduced in 2.4 in IgniteSpringBean to delay ignite instance start until all other spring beans are initialized may have broken Ignite SpringTransactionManager resulting in inability to configure it for Spring transaction abstraction of Ignite transactions. I really, badly need to find a way to work around this. Any ideas/suggestions anyone?

下面是 IgniteSpringBean Java 文档"Ignite 实例在所有其他 Spring bean 初始化之后和 Spring 上下文刷新之前启动.这意味着从任何类型的 Spring bean init 方法(如 PostConstruct)引用 IgniteSpringBean 都是无效的.如果需要的话要为其他 bean 初始化目的引用 IgniteSpringBean,它应该通过在该 bean 中声明的 ContextRefreshedEvent 侦听器方法来完成."

Below is the line from IgniteSpringBean java doc "Ignite instance is started after all other Spring beans have been initialized and right before Spring context is refreshed. That implies that it's not valid to reference IgniteSpringBean from any kind of Spring bean init methods like PostConstruct. If it's required to reference IgniteSpringBean for other bean initialization purposes, it should be done from a ContextRefreshedEvent listener method declared in that bean. "

问题是,因为 SpringTransactionManager 实现了 org.springframework.beans.factory.InitializingBean &在 spring 调用的 afterPropertiesSet() 调用中,它尝试查找指定的 igniteInstanceName 但由于实例仅在所有其他 Spring bean 初始化之后才启动,它因 IgniteIllegalStateException 而失败强>,

The problem is since SpringTransactionManager implements org.springframework.beans.factory.InitializingBean & in the afterPropertiesSet() call that spring calls it tries to look for the igniteInstanceName that's specified but since the instance is started only AFTER all other Spring beans have been initialized, it fails with IgniteIllegalStateException,

请参阅下面的堆栈跟踪,

Please see below stack trace,

lass]:调用init方法失败;嵌套异常是类 org.apache.ignite.IgniteIllegalStateException:提供名称的 Ignite 实例不存在.您是否调用 Ignition.start(..) 来启动 Ignite 实例?[名称=对象管理器网格]在 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)在 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)在 org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)在 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)在 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)在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)在 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:提供名称的点燃实例不存在.您是否调用 Ignition.start(..) 来启动 Ignite 实例?[名称=对象管理器网格]在 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个常用帧

lass]: Invocation of init method failed; nested exception is class org.apache.ignite.IgniteIllegalStateException: Ignite instance with provided name doesn't exist. Did you call Ignition.start(..) to start an Ignite instance? [name=ObjectManagerGrid] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) at 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) at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) Caused by: org.apache.ignite.IgniteIllegalStateException: Ignite instance with provided name doesn't exist. Did you call Ignition.start(..) to start an Ignite instance? [name=ObjectManagerGrid] at org.apache.ignite.internal.IgnitionEx.grid(IgnitionEx.java:1376) at org.apache.ignite.Ignition.ignite(Ignition.java:530) at org.apache.ignite.transactions.spring.SpringTransactionManager.afterPropertiesSet(SpringTransactionManager.java:357) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ... 22 common frames omitted

谢谢

推荐答案

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

For other facing this issue, as commented by Dennis (@dmagda) it has been fixed with this ticket, https://issues.apache.org/jira/browse/IGNITE-8740 & will be available in 2.6.

与此同时,我为解决这个问题所做的是在配置 bean (@Configuration) 中以这种方式破解注入,

In the meanwhile what i did to work around this is to hack the injection this way in a configuration 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;
    }

}

这篇关于IgniteSpringBean &Ignite SpringTransactionManager 在 2.4 中不再协同工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆