Turn off org.springframework.web.servlet.mvc.annotation.Defa



如何关闭org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping detectHandlers,我将spring3启动置于调试模式,我看到所有类都调用"detectHandlers'

示例

[org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping detectHandlers org.springframework.web.servlet.handler.AbstractDetectingUrlHandlerMapping.detectHandlers(AbstractDetectingUrlHandlerMapping.java:86)] - Rejected bean name 'org.springframework.security.authenticationManager': no URL paths identified
[org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping detectHandlers org.springframework.web.servlet.handler.AbstractDetectingUrlHandlerMapping.detectHandlers(AbstractDetectingUrlHandlerMapping.java:86)] - Rejected bean name 'systemProperties': no URL paths identified
[org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping detectHandlers org.springframework.web.servlet.handler.AbstractDetectingUrlHandlerMapping.detectHandlers(AbstractDetectingUrlHandlerMapping.java:86)] - Rejected bean name 'systemEnvironment': no URL paths identified

只有我的"控制器"类有处理程序,而所有其他类都没有。我正在努力加快春季启动的速度。无论如何,要为每个类关闭这个自动检测处理程序功能吗?

您可以使用过滤器跳过不必要的类:

<beans>
   <context:component-scan base-package="org.example">
      <context:exclude-filter type="regex" expression=".*NotControllerBean"/>
   </context:component-scan>
</beans>

对我来说,最高效、最清晰的解决方案是将控制器移动到专用包中,并仅使用此包进行组件扫描。

"只有我的"控制器"类有处理程序,所有其他类都没有"

你是对的。为了知道一个类是否是控制器,Spring必须检查它。这正是你在这里看到的:Spring在类型级别上寻找@Controller@RequestMapping的存在。

最新更新