Announcement Announcement Module
Collapse
No announcement yet.
Inheritence of Injection? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Inheritence of Injection?

    Hi, I'm working on a application based on several Services. I have some functionality that all services should have in common for example: all services should have functionality injected to send an email.
    So i tried to create a base Service and injected the email functionality into it and let all other services extend this service. Unfortunately the property taht contains the Email functionality remains null in all extending services.

    my configuration looks like this:
    Code:
    	<bean id="service"
    		class="net.sequax.loginTest.service.Service">
    		<property name="mailService" ref="mailService"/>
    	</bean>
    	
    	<bean id="mailService"
    		class="net.sequax.mail.MailService">
    	</bean>
    
    	<bean id="someTestService"
    		class="net.sequax.loginTest.service.SomeTestService">
    	</bean>
    the code to call the email function is:
    Code:
    public class SomeTestService extends Service {
    
    	public void handleSth(){
    		super.getMailService().sendEmail();
    	}
    }
    is there another way to somehow pass an injection from a base class to a Service class that inherits from it?

  • #2
    You need to tell the bean what it's parent is. It's not enough to simply extend a class.
    http://www.springframework.org/docs/...an-definitions

    Code:
    	<bean id="someTestService"
    		class="net.sequax.loginTest.service.SomeTestService" parent="service">
    	</bean>

    Comment


    • #3
      Oh yeah, that works.
      Thanks for your incredibly fast reply.

      Comment


      • #4
        Not a problem glad it worked. Remember, the reference manual is your friend .
        http://www.springframework.org/docs/...nce/index.html

        Comment


        • #5
          Originally posted by karldmoore
          Remember, the reference manual is your friend
          You could make a tagline out of that one

          Furthermore indeed you need to tell the beans which parent they should use.

          Comment


          • #6
            , hmmm good idea Marten. Might have to add that one as my signature.

            Comment


            • #7
              Spring docs kick ass

              You are right -- Spring has some of the best docs I've seen. Also if you don't see it in the reference manual, the javadocs are also just plain outstanding

              Charles

              Comment


              • #8
                I would absolutely agree! People get bored of me saying this, but the 2.0 docs are a quantum leap forward. I think they are excellent, just have to keep finding areas to improve on to make them even better .

                Comment

                Working...
                X