开发者

Do i need to make use setter or constructor in DAO implemetaion

I have the class userDAOimpl and i was using

@Resource(name="sessionFactory")
public SessionFactory sessionFactory;

i want to ask that beside that do i need to use setter like

public void setSessionfactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

or

public DAOI开发者_如何学Cmpl(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

One thing is confusing me that how will these get called


Does it make sense to have a DAOImpl instance without session factory. If it doesn't make sense, then it should be in the constructor. This way, a DAOImpl instance is in a valid state once constructed, and is never in an invalid state.

Edit : the session factory should be private, not public.


It depends on whether you are using Property based or constructor based dependency injection. ie.

If you are using Property based then setter is required.

or

If you are using Constructor based then in constructor is required

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜