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 9201109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:55:34+00:00 2026-06-17T22:55:34+00:00

I have two types of controllers in my spring application. View controllers that forward

  • 0

I have two types of controllers in my spring application.

  • View controllers that forward to views to generate HTML
  • API controllers that return JSON directly from the controllers

Both the API and View controllers are part of the same spring dispatcher servlet. Spring 3.2 introduced the @ControllerAdvice annotation to allow for a global location to handle exception.

The documentation implies that @ControllerAdvice will be applied to every controller associated with a Dispatcher Servlet.

Is there a way to configure which controllers @ControllerAdvice will apply to?

For example in my scenario I want a @ControllerAdvice for my View Controllers and separate @ControllerAdvice for my API controllers.

  • 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-17T22:55:35+00:00Added an answer on June 17, 2026 at 10:55 pm

    I do not think this is possible now. If you can make the API and View controllers throw different Exception types, then you could define two different @ExceptionHandlers and achieve what you want.

    // For handling API Exceptions
    @ExceptionHandler(APIException.class)  // Single API Exception 
    @ExceptionHandler({APIException.class, ..., ,,,}) // Multiple API Exceptions
    
    // For handling View Exceptions
    @ExceptionHandler(ViewException.class) // Single View Exception
    @ExceptionHandler({ViewException.class, ..., ...}) // Multiple View Exceptions
    

    You could use aop to translate the Exceptions coming out of APIs to a standard APIException. See this thread on spring forums.

    Hope it helps.

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

Sidebar

Related Questions

I am developing a application to create chart. I have two types of Queries.
I have two user types in my application: Investors and Advisors , they both
I have a view that has two buttons(First and Second) and one hidden field.
I have a table, using display tag, in my application, that is using spring
I'm designing an application that has two [three including administrators] user types: Buyers and
Want to use two models in one view. I have two controllers one for
I have two types of users for my system, normal human users with a
I have two types of registration, registration A and registration B, each will have
I have two types of data sets. Both are in same size. One contains
I have two types of users on the database: -Web registered users -Twitter users

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.