views:

141

answers:

2

@Repository @Service @Controller @Component

-->only use for spring managed bean (no need weaving)
-->@repository, @Service @controller is actually a @Component , just naming easier for programmer to understand

@Configurable

--->used for non spring managed bean (use with weaving)

@Autowired

--> use for DI for both cases above

Is my understanding correct?

+2  A: 

All but @Configurable are correct. From the Spring javadocs:

public @interface Configurable Marks a class as being eligible for Spring-driven configuration. Typically used with the AspectJ AnnotationBeanConfigurerAspect.

duffymo
+1  A: 

Hi,

Spring annotations draws different purposes. As you know Spring heavily uses proxies in order to provide its funcionality. But this funcionality depends on the target annotation.

So when you put

@Repository
public class UserRepositoryImpl implements UserRepository {

    public void saveUser(User user) {
        // logic goes here
    }

}

You are saying

Spring, proxy my UserRepositoryImpl and if it throws any database exception, caught it and re-throw it as a DataAccessException, a generic Spring database exception

And so on...

regards,

Arthur Ronald F D Garcia