Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Scopes for @Rest #207

Description

@pyricau

The @Rest generated implementation rely on a RestTemplate instance. Currently, each injection of an @Rest annotated interface leads to the creation of a new instance of the class implementing this interface.

Users can customize the RestTemplate instance, but they have to do it on a per implementation instance bases, which isn't great. This also leads to the creation of a lost of RestTemplate instance.

We could either :

  • Let @Rest implementations be singletons. But there might be cases where one need different configurations and thefore different instances
  • Allow scope configurations (singleton / prototype / context?). In such a case, we must decide what's the best "default". It's probably singleton, but since @EBean has a default on prototype, maybe we should emphasize coherence

By the way, this isn't totally related, but maybe we should create an interface with setRestTemplate() and getRestTemplate() methods, and let @Rest clients implement it, rather then defining the methods in the interface ?

Activity

  1. JoanZapata commented on May 27, 2012

    @JoanZapata
    Contributor

    When would be the good time to configure a singleton scoped @Rest service ?

  2. JoanZapata commented on May 27, 2012

    @JoanZapata
    Contributor

    I'll explain a little bit more. :)
    I think the current best "workaround" is to have an singleton scoped @EBean that wraps the @Rest class. The @EBean can configure the RestTemplate once, when it's initialized.
    If you have a Singleton scoped @Rest class, you don't know if it has been initialized or not when you come to use it. That's why I asked "when" to configure it.

  3. pyricau commented on May 27, 2012

    @pyricau
    ContributorAuthor

    Hum. You're definitely right, I hadn't thought about this.

    In general, you won't get to use it before all the beans have been injected. So you could configure it in one of the beans @AfterInject method. However, this isn't a really good solution. When looking at the interface, you will have hard times finding where it is configured. So I guess we'd need to specify a "Configurator" bean on the Rest interface ?

  4. JoanZapata commented on May 27, 2012

    @JoanZapata
    Contributor

    Yep, that would be a lot better, I think we agree that the code which uses the @Rest service shouldn't have to worry about the configuration anyway.

  5. ealden commented on Jul 2, 2012

    @ealden
    Contributor

    Are we considering this for 2.7? I'm not sure of the complexity but I would like to give a hand to get this in as we are using it.

  6. pyricau commented on Oct 18, 2012

    @pyricau
    ContributorAuthor

    Still open if you want to give a hand :) . We're going to release 2.7 before Devoxx.

    I'm not exactly sure how we will solve this though.

  7. WonderCsabo commented on Jun 9, 2015

    @WonderCsabo
    Member

    Singleton client would be indeed useful. It is very bad we have to set the common headers after each injection etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions