Results 1 to 7 of 7

Thread: @Service and @Controller on one class

  1. #1
    Join Date
    Sep 2012
    Posts
    4

    Default @Service and @Controller on one class

    Hi,

    I would like to build a REST API for my services in Spring.
    I don't see any need for additional layer of controller classes.
    I would just like to remote those services in a REST API by marking my @Service class with an @Controller annotation and adding proper annotations to methods from String MVC.

    The question is: em I doing it wrong ?

    will this still be treated as an service to which I can add transactional and aspect orientated features ?

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    Transactions or any other aspect oriented feature doesn't depend on @Service it can be on anything...

    I still would go with an additional integration layer the (@Controller annotated classed) ... Just for the sake of clarity and design. A class should have only one reason to change and now you are mixing 2 different things (business and integration/translation) into a single layer. However that is just me...

    Again there is nothing preventing you from putting a @Controller on there and also an @Transactional nothing is bound to either @Service or any other annotation.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Sep 2012
    Posts
    4

    Default

    Thanks for the replay.

    But I wonder from a design point of view would an additional layer add any value if I treat the MVC annotations in this case only as a remoting option.
    Other remoting options in Spring (HTTP invoker, Hessian, etc.) don't encourage an additional layer as I recall.

    PS. Of course I have an additional controller layer for the applications web GUI and presentation.
    Last edited by walec51; Oct 1st, 2012 at 08:30 AM.

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default


    Other remoting options in Spring (HTTP invoker, Hessian, etc.) don't encourage an additional layer as I recall.
    Not explicitly howewver there is one automatically generated for you. So there still is a layer in the other spring remoting implementations that convert from the specific implementation (RMI, hessian, burlap) to your own implementation (actually only a RemoteInvocation is being transfered which contains all the information).

    Note you might want to look at Spring Data Rest which does more or less the same for repositories.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Sep 2012
    Posts
    4

    Default

    Looked into Spring Remoting but nothing seamed to fit my requirements.
    However I also found Apache CXF on the net and it seams to do exactly what I want with little effort. I can expose a HTTP/JSON API for C# and JavaScript developers using the simple JAX-WS annotations. The whole API is generated on a CoC basis but its ok for me. And its well integrated with Spring.

  6. #6
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    Why did you look at Spring Remoting? I mentioned Spring Data Rest not Spring Remoting?!
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  7. #7
    Join Date
    Sep 2012
    Posts
    4

    Default

    Quote Originally Posted by Marten Deinum View Post
    Why did you look at Spring Remoting? I mentioned Spring Data Rest not Spring Remoting?!
    Yes. I looked on both.

    I think I expressed my self incorrectly in my first post. What I really meant by a REST API is a HTTP/JSON service-orientated API.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •