Results 1 to 8 of 8

Thread: Best practices for annotation-based beans?

  1. #1

    Default 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. #2
    Join Date
    May 2006
    Posts
    112

    Default

    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.

  3. #3

    Default

    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

  4. #4
    Join Date
    May 2006
    Posts
    112

    Default

    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

  5. #5

    Default

    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

  6. #6
    Join Date
    May 2006
    Posts
    112

    Default

    JPA is part of JSR

  7. #7
    Join Date
    Aug 2006
    Posts
    113

  8. #8

    Default

    Quote 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

Tags for this Thread

Posting Permissions

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