Announcement Announcement Module
Collapse
No announcement yet.
@Service into @Service Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @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
    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

    Comment


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

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

      i just removed the @Scope and it workd

      thanks :}

      Comment


      • #4
        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

        Comment


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



          att,

          Comment

          Working...
          X