IgniteSpringBean getter method for IgniteConfiguration

classic Classic list List threaded Threaded
3 messages Options
ksamborn ksamborn
Reply | Threaded
Open this post in threaded view
|

IgniteSpringBean getter method for IgniteConfiguration

Hi -

We are beginning to use Ignite and will be instantiating IgniteSpringBean for use within our development sandbox.  I am new to JavaBeans, Spring and Ignite, so forgive me if this is a novice question.

We want to be able to use Spring Boot’s automatic configuration using Java configuration without XML, and are trying to set Ignite properties at runtime via Spring properties files, for example:

ignite.configuration.metrics-log-frequency=0
ignite.configuration.grid-name=MyDataGrid

However, when I try and bind properties of the IgniteSpringBean.IgniteConfiguration inner bean, Spring fails with the following error:

Caused by: org.springframework.beans.NotReadablePropertyException: Invalid property 'configuration' of bean class [org.apache.ignite.IgniteSpringBean]: Bean property 'configuration' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?

When looking at the IgniteSpringBean class, I realized it uses a JavaBeans non-standard getter naming:

--
IgniteConfiguration configuration()
Gets the configuration of this grid instance.

void setConfiguration(IgniteConfiguration cfg)
Sets grid configuration.
--

I believe this is causing Spring to not be able to bind the configuration() method.  

I tried to work around this with by subclassing IgniteSpringBean and it seems to work:

@Configuration
public class MyComputeGrid {
       
        @Bean
        @ConfigurationProperties(prefix="ignite", ignoreUnknownFields=false)
        public MyIgniteSpringBean createIgnite() {
                MyIgniteSpringBean isb = new MyIgniteSpringBean();
               
                return isb;
        }

        // workaround the non-standard getter method of IgniteSpringBean
        //
        static private class MyIgniteSpringBean extends IgniteSpringBean {
            public IgniteConfiguration getConfiguration() {
                return configuration();
            }
        }
}

Am I missing the right way to do this?   Is there another way to make this work?

Thank you very much.

Kevin
vkulichenko vkulichenko
Reply | Threaded
Open this post in threaded view
|

Re: IgniteSpringBean getter method for IgniteConfiguration

Kevin,

That's a good point. I created a ticket to fix this: https://issues.apache.org/jira/browse/IGNITE-1102

Are you OK with your current workaround?

-Val
ksamborn ksamborn
Reply | Threaded
Open this post in threaded view
|

Re: IgniteSpringBean getter method for IgniteConfiguration

Hi Val -

Sure, for now!   I also realized that I could actually great a custom BeanInfo, but I think it's better to fix it.

Thank you very much for your reply.

Kevin