Announcement Announcement Module
Collapse
No announcement yet.
Best practices for annotation-based beans? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Best practices for annotation-based beans?

    Hi,

    I've look at the maven project that I built and decided to break things down into smaller modules to facilitate code-reuse. Conceptually, it is fairly simple to do - break things down into modules with the least dependencies, and have the app provide all the glue logic.

    In theory, this works fine. I am able to break apart my code that way for the things I want to split up. My problem that I am running into is Spring annotations.

    Although the module itself has no reliance on Spring, annotations such as @Autowire, @Repository, @Transactional make the module spring centric.

    I'm not sure of the proper way to proceed. I can eliminate the @Autowire and have the container app do the wiring (using XML or java-based configs), but not sure what to do about the @Repository or @Transactional annotations.

    Are there suggestions or best practices as to how to do this?

    Thanks,

    Eric

  • #2
    i don't know about @repository but for @transactional you can set up aop pointcuts and advice them based on get or set or other such expressions. there are examples in the reference doc that can help you with it.

    Comment


    • #3
      Sure, but that means additional configuration (pointcuts) and quite frankly, am not even sure how the best way to do it would be. I would need some other type of annotation to make it as flexible as possible, and then put a pointcut around that in my app. But it still seems a little impractical, and I figured there must be a much better solution out there to figure out how to do these things.

      Thanks,

      Eric

      Comment


      • #4
        Before I used annotations, in my case we had the entire application that had no reference to spring. All the wiring was done in the application-context (split into dao, service and web). We could have just as easily moved to an ejb container for transactions and struts for web.

        Since you are open to xml or java based configs... There is actually no need for annotations to get rid of @transactional... You will need to use regular expressions to create the point cuts. I currently do not use annotations for aop and define point cuts in XML.

        The reference docs use the most generic cases for a crud application and they seem to cover almost all cases.

        Also you could have spring free but annotated code if you use JSR annotations

        Comment


        • #5
          I was looking into JSR annotations. I'm okay with doing the wiring by hand for these modules, as it kind of makes sense. But for things like @Transactional, I would rather not have to know which methods are or are not transactional.

          What JSR annotation is equiv to @Transactional that Spring supports?

          Thanks,

          Eric

          Comment


          • #6
            JPA is part of JSR

            Comment


            • #7
              @TransactionAttribute ? http://download.oracle.com/javaee/5/...Attribute.html

              Comment


              • #8
                Originally posted by some one View Post
                JPA is part of JSR
                Sure - but the @Transactional annotation is part of the springworks package. Is there an equiv @Transactional annotation in javax that Spring recognizes?

                Thanks,

                Eric

                Comment

                Working...
                X