Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8821537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:52:49+00:00 2026-06-14T05:52:49+00:00

Does it make sense to have an annotated (@Controller) Abstract class in Spring MVC

  • 0

Does it make sense to have an annotated (@Controller) Abstract class in Spring MVC driven container, basically would like to place most of the reusable methods such as exception handlers in the Abstract class and extend that with the base class, so that don’t have to repeat the same boilerplate code. For example.

Abstract Controller Class:

    @Controller
    abstract class AbstractExternalController {

    @ExceptionHandler(NoSuchRequestHandlingMethodException.class)
    @ResponseStatus(value = HttpStatus.NOT_FOUND)
    public @ResponseBody ResponseModel handleNotFoundException() {
            final ResponseModel response = new ErrorModel();
            response.setStatus("404");
                response.setMessage("Resource Not Found");
                return response;
             } 
...

    }

Base Controller Class

@Controller
class ExternalControllerXXX extends AbstractExternalController  {

...
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:52:51+00:00Added an answer on June 14, 2026 at 5:52 am

    It is unnecessary to annotate your AbstractExternalController class with the @Controller anntation, although, leaving it there will not break anything. Regardless of whether or not you have the @Controller annotation, you certainly can have the method annotations, and they will work. Your ExternalControllerXXX extending it will be added to the application context (because it is annotated with a streotype annotation), and the @ExceptionHandler and @ResponseStatus annotations will be honored.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why does it make sense to have Runtime Exceptions UnChecked (as opposed to if
When managing shader's, does it make sense to have all of them compiled and
I have two questions. Does it make sense when I have to choice of
Given that I have a custom PHP error handler already, does it make sense
Ok, question does not really make sense. Here is the situation. I have legacy
Similar question to, Does it make sense to have multiple tomcat instances on the
Does it make sense to have such functions defined let squash12 (e:('a*('b*'c) )) =
Does it make sense to have a @OneToOne member contain a @ForiegnKey annotation. @Entity
Does it make sense to have the maxBufferPoolSize value smaller than maxBufferSize? From my
Hey guys, does it make sense to have a submit button within the definition

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.