Victor Khovanskiy
Victor Khovanskiy

Reputation: 339

Controller exclusion does not work

I have 2 artifacts which are included to main project. The first one contains package "com.parent.controller". The second - "com.child.controller".

Each package contains one contoller - ParentController and ChildContoller, respectively. Both of them have the same RequestMapping (for example just "/abc"). Also I have included exlude filter for ParentController. But in any case I have an exception: java.lang.IllegalStateException: Ambiguous mapping. How to fix it?

@SpringBootConfiguration
@EnableAutoConfiguration
@EntityScan(basePackages = {"com.parent", "com.child"})
@ComponentScan(basePackages = {"com.parent", "com.child"}, excludeFilters = {
    @ComponentScan.Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
    @ComponentScan.Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class),
    @ComponentScan.Filter(type = FilterType.REGEX, pattern = "com\\.parent\\..*Controller"),
    @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = ParentController.class)
})

UPD 1. The packages hierarchy:

- com
  - parent
    - controller
      - ParentController
    - service
    - dao
    - entity
  - child
    - controller
      - ChildController
    - service
    - dao
    - entity

Upvotes: 2

Views: 102

Answers (1)

Abhijit Sarkar
Abhijit Sarkar

Reputation: 24637

Don't scan com.parent root package. Scan each sub package separately, like com.parent.entities. Won't need the exclude then. If that doesn't work, post the parent and child package hierarchy for specific instructions.

Upvotes: 2

Related Questions