话题 首页 > JSP 教程 > JSP 教程话题列表 > 详情

Spring MVC 只扫描controller 和去除controller 都什么用

精华
engyialone 2016-10-21 02:36:54 浏览(4817) 回复(4) 赞(0)

两段代码贴出来

<!-- 扫描的包路径 去掉Controller注解 -->
<context:component-scan base-package="com.yuxuan66.yxbaseframe">
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<!-- 只扫描Controller 注解 -->
<context:component-scan base-package="com.yuxuan66.yxbaseframe"
use-default-filters="false">
<context:include-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
<context:include-filter type="annotation"
expression="org.springframework.web.bind.annotation.ControllerAdvice" />
</context:component-scan>
这两项配置到底有什么用? 有什么好处?

spring mvc

回答(4)

厦门小懒懒 2016-10-21

Spring MVC管理Controller,Spring 管理Controller之外的Bean,去除Controller应该是Spring的配置吧

exclude-filter 要排除的。 include-filter 要包含的。 use-default-filters="false" 不用默认的过滤器扫描代码中的@Controller等注解

一笔荒芜 2018-05-31

大神在哪里呀,大神在哪里呀,大神在哪里呀.

1144100656 2018-05-31

留名留名!!!,同样的问题,看看咋结局!!!

1152696398 2018-05-31

这个领域不太懂!! 还是坐等大佬吧...

要回复,请先登录 或者注册