Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] Add possibility to enable "spring-aware" mode programmatically #6514

Closed
dtitov opened this issue Oct 20, 2015 · 12 comments

Comments

Projects
None yet
6 participants
@dtitov
Copy link

commented Oct 20, 2015

Hi!

According to last comments in thread (#5323 (comment)) the need to have possibility to enable "spring-aware" mode programmatically had appeared.

Probably that can be achieved via introducing a system property and/or @EnableSpringAware like annotation.

@dsukhoroslov

This comment has been minimized.

Copy link
Contributor

commented Oct 26, 2015

The Config class should get isSpringAware/setSpringAware methods, probably?

@dtitov

This comment has been minimized.

Copy link
Author

commented Oct 27, 2015

Yes, that would be nice, I guess.

@dtitov

This comment has been minimized.

Copy link
Author

commented Nov 8, 2015

How's it going, guys?

@mesutcelik mesutcelik modified the milestones: 3.7, Backlog Nov 9, 2015

@mesutcelik

This comment has been minimized.

Copy link
Contributor

commented Nov 9, 2015

We are in Feature Freeze now so we can't add new features into current release(3.6).However, this request is one of the items that we might put into next release(3.7).

please follow-up this issue for the progress.

many thanks.

@dtitov

This comment has been minimized.

Copy link
Author

commented Jan 31, 2016

Sorry for bothering, but is there any update? What are the plans about 3.7 release and about this feature?

@emrahkocaman

This comment has been minimized.

Copy link
Contributor

commented Feb 5, 2016

Hi @dtitov ,

Here is the code snippet to enable SpringAware annotation programmatically.

    @Bean
    public SpringManagedContext managedContext() {
        return new SpringManagedContext();
    }

    @Bean
    public HazelcastInstance instance() {
        Config config = new Config();
        config.setManagedContext(managedContext());
        return Hazelcast.newHazelcastInstance(config);
    }

I've also created a sample project;
https://github.com/hazelcast/hazelcast-code-samples/tree/master/hazelcast-integration/springaware-annotation

Can you please give this a try and share the results with us?

@dtitov

This comment has been minimized.

Copy link
Author

commented Feb 7, 2016

Thank you! That works perfectly.

@messo

This comment has been minimized.

Copy link
Contributor

commented Feb 7, 2016

@emrahkocaman wouldn't the method invocation of managedCotnext() will create a new object? I would write the following:

    @Bean
    public SpringManagedContext managedContext() {
        return new SpringManagedContext();
    }

    @Bean
    public HazelcastInstance instance(SpringManagedContext managedContext) {
        Config config = new Config();
        config.setManagedContext(managedContext);
        return Hazelcast.newHazelcastInstance(config);
    }
@dtitov

This comment has been minimized.

Copy link
Author

commented Feb 7, 2016

@messo , I guess if you call managedContext() within Spring configuration class, it returns the singleton instance of a bean without creating new one.

@messo

This comment has been minimized.

Copy link
Contributor

commented Feb 7, 2016

@emrahkocaman @dtitov thanks, I had to check it, but yes indeed, it seems the whole config class is enhanced as a CGLIB proxy, and the method invocation of managedContext() goes through the same proxy. Thanks! :)

@dtitov

This comment has been minimized.

Copy link
Author

commented Feb 7, 2016

Thanks for checking it, now we know it for sure :)

@emrahkocaman

This comment has been minimized.

Copy link
Contributor

commented Feb 7, 2016

@dtitov @messo Thanks for trying this out guys. Invoking @Bean annotated methods within a @Configuration annotated class should not be a problem since the config class is subclassed with CGLIB.
http://docs.spring.io/spring/docs/current/spring-framework-reference/html/beans.html#beans-java-further-information-java-config

I'm closing this issue then. Please do not hesitate to reopen it if you've problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.