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

  • Is this the idea of Dependency Injection?

    Hi all,

    I'm in my first Spring Web App (i've been working with struts for years) and i've started with a small demo. It's running ok, i wanna know if i'm missing something before i start with the real app.

    Forms and FormControllers work well, because they work like Struts Actions and Action Forms. But how can i call a method in a TestBusinessObj from my TestFormController? And this is just the start, because my TestBusinessObj has to call a method in my TestDAO ....

    I've done like this:

    In my app-servlet.xml i've defined my controller like this:
    <bean name="TestFormController" lass="test.TestFormController">
    <property name="businnesObj" ref="TestBO"/>
    </bean>
    And my applicationContext.xml is this:
    <bean name="TestDAO" class="test.TestDAO"/>
    <bean name="TestBO" class="test.TestBO">
    <property name="dao" ref="TestDAO"/>
    </bean>
    Obiously, my testBO has a property named 'dao', and my TestFormController has a property named ''businnesObj'.

    Doing like this, in TestFormController i only have to do something like:
    businnesObj.insert(testForm);
    My questions are:

    1.- Is this ok? I think this is the idea of Dependency Injection but i'd prefer to be sure

    2.- My DAO does nothing, but i suposse i'll have to inject it a DataSource so it can access a database, won't i?

    3.- Should i use only one XML for all the beans, or it's ok to use these 3:

    - applicationContext.xml for BusinessObjs and DAOs
    - app-servlet.xml for Controllers
    - app-views for Views
    Thanks,

    Keko

    PS: Sorry for my English, i'm still studying
Working...
X