Jul 12th, 2011, 01:31 PM
Best practices for annotation-based beans?
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?
Jul 12th, 2011, 05:58 PM
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.
Jul 12th, 2011, 09:26 PM
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.
Jul 12th, 2011, 10:36 PM
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
Jul 12th, 2011, 10:57 PM
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?
Jul 13th, 2011, 03:19 PM
Jul 13th, 2011, 04:37 PM
Jul 13th, 2011, 10:24 PM
Sure - but the @Transactional annotation is part of the springworks package. Is there an equiv @Transactional annotation in javax that Spring recognizes?
Originally Posted by some one
Tags for this Thread