struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jozef Fiflik <>
Subject Re: Struts2 + Spring/Hibernate
Date Fri, 13 Nov 2009 10:05:04 GMT

I've just created similar skeleton couple of days ago.

To let Spring generate your Service and DAO beans, you have to specify also
the GenericService and GenericDAO in your applicationContext xml. You (can)
set them as abstract and you have to specify the inheritance relationship
between the PersonDAO and GenericDAO, the same for Service of course.

At least this worked for me...

Regarding your design... I thought that DAO design pattern is here to handle
access to data objects, i.e. CRUD. So I don't see the benefit of the Service
here? Can someone explain this? In my application I don't have any business
logic but CRUD. Is the Service layer needed here or can DAO act as the
Service as well?

And finally I've got one more question, which I believe is related to
this... One thing everyone suggest is to use wildcards in the Struts2
web.xml for CRUD operations. But this reference to many action classes with
the same functionality. My question is, if we remove the duplicity in
web.xml, can't we remove the duplicity in the Java code as well? Can't we
create generic CRUD action as well? (Similar to generic DAO or generic


On Fri, Nov 13, 2009 at 12:47 AM, CRANFORD, CHRIS <
> wrote:

> I am in the process of implementing Struts2 along with integrated
> support with Spring and Hibernate.  While I have found various examples
> on the web, I tend to find they vary.  My application will primarily
> focus about 75% of the time on data queries and displaying this data to
> end users while a smaller 25% will actually support a full CRUD based
> system for certain data records.
> So far the examples I have seen have focused on implementing a class
> structure similar to the following:
> The GenericDAO class is a template-like class that holds a reference to
> the EntityManager along with methods for saving, deleting, and
> retreiving objects persisted inside the EntityManager.  The PersonDAO
> object extends GenericDAO and provides an additional list method shown
> below:
> public class PersonDAO extends GenericDAO<Person,Integer> {
>  public List<Person> list(int page, int size) {
>    Query query = this.em.createQuery("from Person order by lastName,
> firstName");
>    query.setFirstResult((page-1) * size);
>    query.setMaxResults(size);
>    return query.getResultList();
>  }
> }
> The Person class itself is annotated as an @Entity object with a unique
> property that is marked as the entity's unique ID and all the properties
> of the Person table along with get/set methods for each property.
> GenericService is another template-like interface class that defines
> create/delete/update/getById/list methods.  Then PersonService
> implements this GenericService interface with calls to the PersonDAO
> object for each of these methods.
> And lastly PersonAction extends ActionSupport and implements
> StrutsStatics where it gets constructed with the GenericService<Person>
> class.
> Inside my web\WEB-INF\myAppContext.xml file I have:
>  <!-- daos -->
>  <bean id="personDao" class=""/>
>  <!-- services -->
>  <bean id="personService"
> class="">
>    <property name="dao" ref="personDao"/>
>  </bean>
>  <!-- actions -->
>  <bean id="personAction" scope="prototype"
> class="">
>    <constructor-arg ref="personService"/>
>  </bean>
> Is there anything else I should include in myAppContext.xml?
> Any special inclusions or statements I need in my
> applicationContext.xml?
> Per one example I saw, struts.xml should be as follows:
>  <package name="persons" namespace="/persons" extends="struts-default">
>    <action name="list" class="personAction" method="list">
>      <result name="success">/WEB-INF/pages/persons/list.jsp</result>
>    </action>
>  </package>
> Thus far this example seemed easy to understand, particularly because
> we're only dealing with a single table.  Before I go into how to take
> this example and build from it, do any of you have any input or
> suggestions on the approach I am taking with objects?  Any lessons
> learned?
> Thanks
> Chris
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message