Both @Component and @Named for the same bean class

@Component and @Named are annotations that basically do the same thing, but come from different APIs.

@Component belongs to Spring API. It marks class to be autodetected as a bean and optionally allows you to specify a name for that bean (@Component("foo")). Without explicit name specification detected bean will get a default name derived from the name of its class.

@Named belongs to javax.inject API. It marks class to be autodetected as a bean and requires you to specify a name.

Spring supports both these APIs. It doesn’t make sense to use both annotations at the same class since they provide the same functionality.

See also:

  • 3.10 Classpath scanning and managed components

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)