You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by Guilherme Melo <gu...@gmelo.org> on 2017/04/24 10:09:23 UTC
Unable to inject spring configuration on Cachestore
Hello,
I am trying to utilize @SpringResource and
@SpringApplicationContextResource, however both are null on my CacheStore,
has anyone encountered this before?
Below is my config:
@Bean
public IgniteConfiguration getIgniteConfiguration() {
IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setClientMode(false);
CacheConfiguration orderCache = new CacheConfiguration();
orderCache.setName("testCache");
orderCache.setBackups(1);
orderCache.setCacheMode(CacheMode.PARTITIONED);
orderCache.setCacheWriterFactory(FactoryBuilder.factoryOf(CacheStoreWithInjectedBeans.class));
orderCache.setReadThrough(true);
orderCache.setWriteThrough(true);
cfg.setCacheConfiguration(
orderCache);
return cfg;
}
and the class:
public class CacheStoreWithInjectedBeans implements CacheWriter<String,
String> {
@SpringResource
private MyService myService;
@SpringApplicationContextResource
private Object appCtx;
@Override
public void write(Cache.Entry<? extends String, ? extends String>
entry) throws CacheWriterException {
myService.apply(entry.getValue());
}
@Override
public void writeAll(Collection<Cache.Entry<? extends String, ? extends
String>> entries) throws CacheWriterException {
}
@Override
public void delete(Object key) throws CacheWriterException {
}
@Override
public void deleteAll(Collection<?> keys) throws CacheWriterException {
}
}
Cheers,
Guilherme Melo
www.gmelo.org
Re: Unable to inject spring configuration on Cachestore
Posted by Guilherme Melo <gu...@gmail.com>.
Thats great,
Thank you very much Andrey.
Cheers,
Guilherme Melo
www.gmelo.org
On 25 April 2017 at 01:04, Andrey Gura <ag...@apache.org> wrote:
> Hi Guilherme,
>
> Ignite creates Spring application context only if started using
> Ignition.start(springUrlCfg) method and can work only with XML
> application context.
>
> Try to use IgniteSpringBean. This class implements
> ApplicationContextAware interface so your Spring application context
> should be propagated to Ignite instance.
>
> Another way is using IgniteSpring.start() factory method that get
> optional Spring application context.
>
> On Mon, Apr 24, 2017 at 1:09 PM, Guilherme Melo <gu...@gmelo.org>
> wrote:
> > Hello,
> > I am trying to utilize @SpringResource and
> > @SpringApplicationContextResource, however both are null on my
> CacheStore,
> > has anyone encountered this before?
> >
> > Below is my config:
> >
> > @Bean
> > public IgniteConfiguration getIgniteConfiguration() {
> > IgniteConfiguration cfg = new IgniteConfiguration();
> > cfg.setClientMode(false);
> > CacheConfiguration orderCache = new CacheConfiguration();
> > orderCache.setName("testCache");
> > orderCache.setBackups(1);
> > orderCache.setCacheMode(CacheMode.PARTITIONED);
> >
> > orderCache.setCacheWriterFactory(FactoryBuilder.factoryOf(
> CacheStoreWithInjectedBeans.class));
> > orderCache.setReadThrough(true);
> > orderCache.setWriteThrough(true);
> >
> > cfg.setCacheConfiguration(
> > orderCache);
> > return cfg;
> > }
> >
> > and the class:
> >
> > public class CacheStoreWithInjectedBeans implements CacheWriter<String,
> > String> {
> > @SpringResource
> > private MyService myService;
> > @SpringApplicationContextResource
> > private Object appCtx;
> > @Override
> > public void write(Cache.Entry<? extends String, ? extends String>
> entry)
> > throws CacheWriterException {
> > myService.apply(entry.getValue());
> > }
> > @Override
> > public void writeAll(Collection<Cache.Entry<? extends String, ?
> extends
> > String>> entries) throws CacheWriterException {
> >
> > }
> > @Override
> > public void delete(Object key) throws CacheWriterException {
> >
> > }
> > @Override
> > public void deleteAll(Collection<?> keys) throws
> CacheWriterException {
> >
> > }
> >
> > }
> >
> > Cheers,
> > Guilherme Melo
> > www.gmelo.org
>
Re: Unable to inject spring configuration on Cachestore
Posted by Andrey Gura <ag...@apache.org>.
Hi Guilherme,
Ignite creates Spring application context only if started using
Ignition.start(springUrlCfg) method and can work only with XML
application context.
Try to use IgniteSpringBean. This class implements
ApplicationContextAware interface so your Spring application context
should be propagated to Ignite instance.
Another way is using IgniteSpring.start() factory method that get
optional Spring application context.
On Mon, Apr 24, 2017 at 1:09 PM, Guilherme Melo <gu...@gmelo.org> wrote:
> Hello,
> I am trying to utilize @SpringResource and
> @SpringApplicationContextResource, however both are null on my CacheStore,
> has anyone encountered this before?
>
> Below is my config:
>
> @Bean
> public IgniteConfiguration getIgniteConfiguration() {
> IgniteConfiguration cfg = new IgniteConfiguration();
> cfg.setClientMode(false);
> CacheConfiguration orderCache = new CacheConfiguration();
> orderCache.setName("testCache");
> orderCache.setBackups(1);
> orderCache.setCacheMode(CacheMode.PARTITIONED);
>
> orderCache.setCacheWriterFactory(FactoryBuilder.factoryOf(CacheStoreWithInjectedBeans.class));
> orderCache.setReadThrough(true);
> orderCache.setWriteThrough(true);
>
> cfg.setCacheConfiguration(
> orderCache);
> return cfg;
> }
>
> and the class:
>
> public class CacheStoreWithInjectedBeans implements CacheWriter<String,
> String> {
> @SpringResource
> private MyService myService;
> @SpringApplicationContextResource
> private Object appCtx;
> @Override
> public void write(Cache.Entry<? extends String, ? extends String> entry)
> throws CacheWriterException {
> myService.apply(entry.getValue());
> }
> @Override
> public void writeAll(Collection<Cache.Entry<? extends String, ? extends
> String>> entries) throws CacheWriterException {
>
> }
> @Override
> public void delete(Object key) throws CacheWriterException {
>
> }
> @Override
> public void deleteAll(Collection<?> keys) throws CacheWriterException {
>
> }
>
> }
>
> Cheers,
> Guilherme Melo
> www.gmelo.org