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

1

6

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
Photophobia answered 29/8, 2010 at 13:0 Comment(0)
N
3

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.

Nosey answered 29/8, 2010 at 13:21 Comment(3)
The second way should still work with 3.0 The classes are all there: static.springsource.org/spring/docs/3.0.x/javadoc-api/org/…Encomium
My bad. Classes are still there. But most of them are deprecated. Deprecated. as of Spring 3.0, in favor of annotated controllers static.springsource.org/spring/docs/3.0.x/javadoc-api/org/…Nosey
There is no deprecation mentioned in Spring 5: docs.spring.io/spring-framework/docs/current/javadoc-api/org/…Amorphism

© 2022 - 2024 — McMap. All rights reserved.