Spring annotations conflicts with my design guidelines
Overview
Using
@Service
, @Transactional
, @ManagedResource
, @Inject
, etc.) Guidelines highlights
@Repository
or @Service
must have an interface Foo(Bar bar) {...}
) final class Foo
) The Problem
@Transactional
@Service
s are accessed via facade service which requires more than one service to include in the facade transaction (eg Observer service over 2 application components) @Qualifier
) beanRefContext.xml
file to configure its internal application context When I used to work with XML configuration I was able to enforce all the guidelines I presented above, but when switching to annotations it seems like Spring is misbehaving.
Developers in my group prefer annotation configuration (I seems easier to wire and write new code), but I've noticed all kind of "hacks" they introduce to the code to prevent from dealing with Spring application context failures.
The Question(s)
@Primary
or @Qualifier
) @Transactional
@ManagedResource
I came up with the following solution (to questions #2 and #3) to be able to enforce my design guidelines and keep using annotation based configuration:
ApplicationContext
beanRefContext.xml
The above steps also enabled me to reduce the execution time of Spring aware tests (every module loaded only a sub-set of beans).
As a practical guideline (for question #1), if an interface has more than one implementation, I place @Primary
on the widely used one and other clients, requiring another implementation, wire the bean using @Qualifier
.
回答第2点)您可以使用AspectJ代替CGLib。
链接地址: http://www.djcxy.com/p/62812.html上一篇: 为什么我的Spring @Autowired字段为空?
下一篇: Spring注释与我的设计指南相矛盾