2017-08-27 85 views
2

我所包括的主要項目2個假象。第一個包含包「com.parent.controller」。第二個 - 「com.child.controller」。控制器排除不起作用

每個包包含一個位指示 - ParentControllerChildContoller,分別。它們都具有相同的RequestMapping(例如,只是「/abc」)。我還包括ParentController exlude過濾器。但在任何情況下,我有一個例外: java.lang.IllegalStateException: Ambiguous mapping。如何解決它?

@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。軟件包層次結構:

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

什麼是有兩個控制器具有相同映射的原因是什麼? –

+0

@AbhijitSarkar,父項目是外部不可修改的庫。我想重寫它的一些映射。 –

回答

2

不要掃描com.parent根包。分別掃描每個子包,如com.parent.entities。那麼就不需要排除了。 如果這不起作用,請發佈父級和子級包級別以獲取特定說明。

+0

是的,它的工作原理。謝謝。 –