Skip to content

When specified the Non-existent package using @ControllerAdvice(basePackages), has been applied to all controllers. [SPR-12510] #17115

Closed
@spring-projects-issues

Description

@spring-projects-issues

Kazuki Shimizu opened SPR-12510 and commented

e.g)

package io.github.kazuki43zoo.app;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ModelAttribute;


@ControllerAdvice(basePackages = "xxxx")
public class AppControllerAdvice {

    @ModelAttribute("appCommonMessage")
    public String commonMessage() {
        System.out.println("AppControllerAdvice#appCommonMessage() called.");
        return "Hello in AppControllerAdvice.";
    }

}

Above @ModelAttribute method has been applied to the all controllers.( e.g: controllers under io.github.kazuki43zoo.app package).

I think feel unnatural in this behavior.
This behavior is specification ?

As related information ..
When specified the Non-existent package using @ComponentScan(basePackages), controller is not scanned.

I think should be changed to the same behavior with @CompnentScan.

How do think ?


Affects: 4.0.8, 4.1.2

Issue Links:

Backported to: 4.0.9

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: backportedAn issue that has been backported to maintenance branchesstatus: duplicateA duplicate of another issue

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions