Which do you prefer? In spring mvc, they use @Controller for all Controller classes. Could they have used some marker interface? Why did they select the annotation approach?
Better yet, they can have something similar to controller-scan similar to component-scan so any classes in the package can be assumed to a Controller class. Similarly service-scan and repository-scan can be defined in xml.
Which do you prefer? In spring mvc, they use @Controller for all Controller classes.
Share
I think technically the same effect would be possible with marker interfaces. The problem is that marker interfaces are limited to classes and cannot be used for attributes or methods.
Spring is using annotations for adding meta data to attributes (e.g.
@Autowired) or methods (e.g.@RequestMappingor@Transactional). So it is consistent to use the same approach for adding meta data to classes (like@Controlleror@Service)Note that Spring does not force you to use the provided annotations.
@Controllerand@RequestMappingare just the default way to define handler mappings. In theory you can come up with your own way of mapping incoming requests to method calls.