Results 1 to 5 of 5

Thread: @Service into @Service

  1. #1
    Join Date
    Feb 2011
    Posts
    3

    Default @Service into @Service

    Hi guys;
    I have a doubt about how spring works.

    Lets suppose we have 2 classes with the @Service anotation.
    Then i wanna use some functionality from 1 of them into another.
    How can i do it?

    If i m with a lot of misunderstood concepts, can u guys give me a help?

    thanks for your help :}

  2. #2
    Join Date
    Dec 2010
    Location
    Singapore
    Posts
    284

    Default

    Lets suppose we have 2 classes with the @Service anotation.
    Classes that are marked as @Service will get autodetected through classpath scanning.

    Then i wanna use some functionality from 1 of them into another.
    You'll have to wire them-up. Manual or Auto
    Amila Domingo

  3. #3
    Join Date
    Feb 2011
    Posts
    3

    Default

    Thanks,
    i found the problm.
    I marked 1 class with

    @Service("clazname")
    @Scope("session")

    i just removed the @Scope and it workd

    thanks :}

  4. #4
    Join Date
    Nov 2005
    Posts
    113

    Default

    The core problem you're having here is injecting a Session-scoped bean into a Singleton. This can work, but you need to do a little more configuration.

    See, singletons get injected once, at startup. This obviously won't work for session/request scoped beans, since the session isn't available until the request itself is issued. The solution is not to inject the scoped bean, but a proxy to that bean (that will be resolved when the actual call is made).

    With XML, you'd just add a <aop:scoped-proxy/> tag to your scoped bean definition. You can't really do that with annotation-driven configuration, though. Instead, if you set up your component scanning like this:

    Code:
    <context:component-scan base-package="your package" scoped-proxy="interfaces"/>
    Spring will automatically create proxies for all scoped beans discovered through component scanning. This should enable your code to work even with a @Scope("session").

    Hope this helps
    - Don

  5. #5
    Join Date
    Feb 2011
    Posts
    3

    Default

    Thanks for your answer,
    your explanation was very helpful on my understanding about spring



    att,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •