This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

Business Layer for Web Applicatin projects

We generated a web project using Spring Roo. It's pretty awesome since a lot of work is done automatically. I now was wondering, if it's possible to force Spring Roo to use a business layer?

Right now the Spring Controllers access directly the domain models (Data Layer). We would like to use a layer in between to handle the business logic, since we don't want to do it in the web controllers. The reason for that is that we plan to offer a web service in the near future. So it would make sense that both the web application and the web service access the service components. Additionally we don't have to duplicate logic and security constraints.

Comment

Roo can't generate a Services layer for you at this stage (I can't see how they could add much other than placeholder logic to it anyway), but there is nothing stopping you from adding one.

For an app thats going to be large enough, not adding the business logic to the Entities can make a lot of sense. What some people don't seem to have grasped in that the Roo Entity classes are both simultanously ActiveRecord and JavaBean. While design for these are both often abused, they are both intended to be primarily Data Transfer Objects (DTO's).

If you do put business logic in them, you have to watch out for a bunch of traps, especially around the use of javabeans. Many things that act on javabeans expect to be able to call getX on everything, so you never want to add a business method with that name. RooToStrings and Xml/Json serializers especially. (In both cases you can annotate to have them avoid it)