Question

I am new to writing a spring rest based ws. I created a project with the following structure.

Java Resources
  - src/test/java
  - src/main/java
     - com/sample/rest
       - controller  (for the request mappings)
       - domain (for POJOs)
       - service (for business logic)
       - utility (for utility methods)
       - dao (for database calls)

I started adding POJOs in the domain package, but my problem is that I have 2 kinds of POJOs in my application. One type which corresponds to my application table structure. Another type which corresponds to a third party result structure.

I am not sure how I can differentiate these 2 POJO types under my domain package.

Was it helpful?

Solution

most projects look like what you described. Inside domain package would have a user package where it would have all user related pojos. On dao, service would exist the same sub packages too.

But an organization that I think it's best is to split the packages is this way:

-com.company.project
    - users
         UserService
         UserDAO
         User
         Role
    - cart
         Cart
         CartService
         CartDAO
         ShopItem

And so it goes. I saw it for the first time on talk from a guy from Spring Source. I'll try to find the video.

Anyway, I'm working on a project with this strategy for some months, and until now it seems more organized than the traditional way.

If a package, for example users, become too crowded, you can always create subpackages to organize inside it. But for most packages it will be 1 or 2 domain classes, one DAO and one Service. So there's no need for more packages.

Update: I think this is the video: http://www.youtube.com/watch?v=tEm0USdF-70

OTHER TIPS

Lets come think from the module/library point of view.

Good to have separated core business logic library outside the application , keep it separate with the test library, and rest library to embrace the core business logic library by utilize the functionality inside the core business logic.

Module : MyAppLogic.jar
  -> com.company.user
       -> class UserBean : Pojo
       -> class UserDao : insert( String userName , String userEmail ) ;
       -> class UserService : insert( UserBean userBean ) ;
  -> com.company.cart
       -> class CartBean : Pojo
       -> class CartDao : insert( int cartUserId , int cartItemId ) ;
       -> class CartService : insert( CartBean cartBean ) ;

Module : MyAppRest.jar
  -> com.company.rest.domain
       -> class User : @XmlRootElement
       -> class Cart : @XmlRootElement
  -> com.company.rest.model
       -> interface UserServiceIntf : insert( User user ) ;
       -> class UserServiceImpl : private UserService userService ;
       -> interface CartServiceIntf : insert( Cart cart ) ;
       -> class CartServiceImpl : private CartService cartService ;
  -> com.company.rest.service
       -> class UserRestService : @Path("/users")
       -> class CartRestService : @Path("/carts")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top