Reputation: 1494
Overview
Using
@Service
, @Transactional
, @ManagedResource
, @Inject
, etc.)Guidelines highlights
@Repository
or @Service
must have an interfaceFoo(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 (e.g. Observer service over 2 application components)@Qualifier
)beanRefContext.xml
file to configure its internal application contextWhen 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
Upvotes: 4
Views: 1249
Reputation: 1494
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
.
Upvotes: 3