Announcement Announcement Module
Collapse
No announcement yet.
Inject request level object to dao methods Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Inject request level object to dao methods

    Code:
    class Struts2Action extends ActionClass{
       FwBean bean;
       void prepare(){
           bean=generateObject()  // From request and session
       }
    
       @Autowired
       private UserBO userBo;
       
       public String save(){
         userBo.save(userOb);
       }
       
    }
    @Service
    class UserBO {
      @Autowired
      private UserDAO userDao;
      
      public void save(User user){
        userDao.save(user);
      }
    
    }
    
    @Repository
    class UserDAO {
       FwBean fwBean;
       void delete(){}
       void update(){}
       void save(User user){
          user.setModifiedBy(fwBean.getUserID());
    	  user.setRequestFormName(fwBean.getRequestFormName());
    	  em.save(user);
       }
       List<User> get{}
       
       public void setFwObjetc(FwBean bean){
          fwBean=bean;
       }
    }

    see the above source

    we have to generate FwBean object for every new http request and automatically inject to UserDAO methods without extra piece of code

    is there any spring annotation shortcut

  • #2
    Yes, Create a request scoped bean and inject it on Dao

    Cheers

    Comment

    Working...
    X