Announcement Announcement Module
Collapse
No announcement yet.
@Service and @Controller on one class Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @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
    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.

    Comment


    • #3
      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, 09:30 AM.

      Comment


      • #4

        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.

        Comment


        • #5
          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.

          Comment


          • #6
            Why did you look at Spring Remoting? I mentioned Spring Data Rest not Spring Remoting?!

            Comment


            • #7
              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.

              Comment

              Working...
              X