Announcement Announcement Module
No announcement yet.
Interaction of Service Layer Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Interaction of Service Layer

    Hi there!

    I'm newbie to spring. I read the spring-mvc-step-by-step tutorial and successfully integrated hibernate to that example I could make it run without problems.

    From the reading I understood that service layer is the layer where pojos get served, isn't it? From the tutorial example: ProductManager is the service responsible for handling products (Product POJO). So, ProductManager has all "business rules" regarding products such as increasePrice.

    So... what if I have StoreManager which handles Stores (Store POJO) -with methods (business rules) that need make use of other business rules-? For example, StoreManager would have methods such as increaseProductPriceInStoreX, which finds the store "X", do some logic with the store and need to make use of increasePrice from SimpleProduct? How do I achieve that? how do I can use business logic between xyzManagers?

    The first solution that came to my mind was to set productDao in SimpleStoreManager, but in this way I will end up re-writing increasePrice business code in increaseProductPriceInStoreX from SimpleStoreManager.

    How do I can call a "business rule" (increasePrice from ProductManager) from another business handler (StoreManager)?


  • #2
    You can inject your ProductManager into your StoreManager just like any other bean. for example

    <bean id="storeManager" class="....." >
    <property name="storeDAO" ref="storeDAO" />
    <property name="productManager" ref="productManager" />


    • #3
      Thx Chris, I'll implement it Doing so, I have to add a setter for productManager as well, isn't it?

      Would be this the only solution? I'm thinking, what if in the near future I need to add another xyzSimpleManager? is there a way to let spring to "automatically" recognize other SimpleManagers (without adding setters and so)?


      • #4
        You can set the @Autowired annotation to the properties in your class. Just follow the instructions in section 3.11 of the Spring2.5 reference doc.