3

When I am using Spring 3.x While using annotations its difficult for me to know Which type of Controller class we are going to fetch using this @Controller With reference to

http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/servlet/mvc/Controller.html

These are implementing Controller class

AbstractController
AbstractUrlViewController
MultiActionController
ParameterizableViewController
ServletForwardingController
ServletWrappingController
UrlFilenameViewController
AbstractWizardFormController
SimpleFormController

However when we are using @Controller annotation in our Spring MVC program how to know that Our @Controller annotation is implementing any of these controllers, Kindly anyone explain me

1
  • @Controller is quite different from Controller you don't get any of them nor should you mix them as they behave quite differently! Commented Apr 30, 2015 at 11:51

3 Answers 3

3

I think you are missing the point here. In the old times to register a controller, your class must have implemented controller interface and choose request mapping type. Sometimes you had to implement lots of code to achieve single request mapping.

Nowadays, when we have annotations, the model has changed. We can handle multiple request types per controller class. Because in single @Controller annotated class we can handle many request mappings.

Controller annotation is a specialized @Component, that tells Spring that inside it will find @RequestMapping handlers. Those handlers can be used either for returning Json, HTML or for uploading files.

Now logic connected with same module can be placed under single controller class, you are more flexible in what you want to achieve. Secondly @Controller enables us to reduce code anount significantly.

Sign up to request clarification or add additional context in comments.

2 Comments

If i need AbstractWizardFormController then how the Spring understands that I need this, What if I need two or more Controllers inside a Single java code.
2

You aren't using any of those classes. You confuse the Controller interface with the annotation.

The annotation is just a marker that states that your bean is a Spring Controller and can send an receive HTTP requests. http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/stereotype/Controller.html

The Controller interface was introduced when there were no annotations in the Java language.

Comments

2

Which type of Controller class we are going to fetch using this @Controller ?

The @Controller annotation is to tell the web container that this is the controller class for requests with urls specified with @RequestMapping(URI). you are going to fetch no class if you are annotating your class with @Controller , you just need to provide a request handler method within the class and annotate it with @RequestMapping , though the controller class can also be annotated with @RequestMapping and in that case , only method inside the class will work as request handler method.

how to know that Our @Controller annotation is implementing any of these controllers ?

The names of the classes you have mentioned are implementing Controller interface , not that @Controller annotation is implementing anything .Those controller classes are for specific purposes ,as their names suggest .

8 Comments

Ok I Agree..So if i require AbstractWizardFormController whether Can i go with @Controller or implementing AbstractWizardFormController?
you would have to extend the AbstractWizardFormController class .( you know its an abstract class and how abstract are made useful )
Can you please accept the answer ? if it satisfies you .@MSIbrahim
I shall give it to u..but..Currently am using Spring 3.0 & Spring Sec 3.x in this case how shall I use extends AbstractWizardFormController. It is throwing ClassNotFoundException.. There's is a version collapse
you may be missing some jar files or using jars of different version.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.