How to get Spring context

classic Classic list List threaded Threaded
5 messages Options
kcheng.mvp kcheng.mvp
Reply | Threaded
Open this post in threaded view
|

How to get Spring context

Ignition starts with a spring configuration file, is there anyway(static method) to get the spring context?
vkulichenko vkulichenko
Reply | Threaded
Open this post in threaded view
|

Re: How to get Spring context

You can use @IgniteSpringApplicationContextResource annotation to inject app context into tasks, jobs, closures, entry processor and other entities. For example:

private static class MyRunnable implements IgniteRunnable {
    @SpringApplicationContextResource
    private ApplicationContext appCtx;

    @Override public void run() {
        // TODO
    }
}

Will this work for you?

-Val
kcheng.mvp kcheng.mvp
Reply | Threaded
Open this post in threaded view
|

Re: How to get Spring context

My scenario is bit difference with this. i define a some none-ignite related bean/service in the xml configuration. as ignite starts with this xml file, so I guess there might be a xxxContext to get a ignite reference.
vkulichenko vkulichenko
Reply | Threaded
Open this post in threaded view
|

Re: How to get Spring context

It looks like we don't have such a method, but I think it's a good idea to have it. I created a ticket: https://issues.apache.org/jira/browse/IGNITE-1248

As an alternative, you can use Ignition.loadSpringBean(..) method. It will load the context from scratch and retrieve the bean by name. Will this work for you?

-Val
kcheng.mvp kcheng.mvp
Reply | Threaded
Open this post in threaded view
|

Re: How to get Spring context

Yes, that's what am doing right now!