Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between declaring a controller with the Spring Controller stereotype versus as a subclass of the AbstractController?

What's the difference between declaring the TestController with the Spring Controller stereotype like this:

import org.springframework.stereotype.Controller;
//...
@Controller
@RequestMapping("/test")
public class TestController

versus as a subclass of the AbstractController like this:

import org.springframework.web.servlet.mvc.AbstractController;
//...
public class TestController extends AbstractController
like image 385
Gary Ford Avatar asked Nov 06 '22 09:11

Gary Ford


1 Answers

The obvious difference is that with annotations you do not depend on any specific API.

Annotation configuration is available since Spring 2.5 and both configuration give you pretty much the same result. As of Spring 3.0 you cannot use second type of configuration (there simply no classes to extend) and so annotations is all you have.

like image 50
Georgy Bolyuba Avatar answered Nov 10 '22 18:11

Georgy Bolyuba