Saturday, 24 August 2013

Declaration of beans and Dao classes in Spring

Declaration of beans and Dao classes in Spring

Spring give the facility of defining beans class and DAO classes in
application-context.xml file right now i am defining the bean classes like
that
<context:component-scan base-package="com.forum.jsfbeans" />
But many places in google i saw people defined DAO,beans,Service classes
differently something like this
<!-- Beans Declaration -->
<bean id="User" class="com.otv.model.User"/>
<!-- User Service Declaration -->
<bean id="UserService" class="com.otv.user.service.UserService">
<property name="userDAO" ref="UserDAO" />
</bean>
<!-- User DAO Declaration -->
<bean id="UserDAO" class="com.otv.user.dao.UserDAO">
<property name="sessionFactory" ref="SessionFactory" />
</bean>
we have to defined all the classes in application-context.xml file
differently(like i did above) or we can just use the below tag for each
type of classes not a matter its DAO,Bean or Service?
<context:component-scan
base-package="com.forum.dao,com.forum.jsfbeans,com.forum.service" />
If we will defined something like above it will work and Spring know what
action it have to perform in DAO,Service or Bean classes .

No comments:

Post a Comment