The @Repository
annotation is a marker for any class that fulfils the
role or stereotype of a repository (also known as Data Access Object
or DAO). Among the uses of this marker is the automatic translation of
exceptions, as described in Exception Translation.
Spring provides further stereotype annotations: @Component
, @Service
,
and @Controller
. @Component
is a generic stereotype for any
Spring-managed component. @Repository
, @Service
, and @Controller
are
specializations of @Component
for more specific use cases (in the
persistence, service, and presentation layers, respectively).
Therefore, you can annotate your component classes with @Component
,
but, by annotating them with @Repository
, @Service
, or @Controller
instead, your classes are more properly suited for processing by tools
or associating with aspects.
For example, these stereotype annotations
make ideal targets for pointcuts. @Repository
, @Service
, and
@Controller
can also carry additional semantics in future releases of
the Spring Framework. Thus, if you are choosing between using
@Component
or @Service
for your service layer, @Service
is clearly the
better choice. Similarly, as stated earlier, @Repository
is already
supported as a marker for automatic exception translation in your
persistence layer.
Best Answer
I do not believe Application 2 can access application 1's security information. Not directly anyways, perhaps using remoting, or webservices will allow you to do this. However, I do not think there is a place in the spring security framework where you can go across applications and get information though java code only.