2017-08-27 88 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

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