StringMVC定时任务执行两次,Tomcat启动时myThreadPoolTaskExecutor、getExecutor初始化两遍

99 阅读1分钟

StringMVC定时任务执行两次,Tomcat启动时myThreadPoolTaskExecutor、getExecutor初始化两遍 是context:component-scan配置问题
修改前:

<!-- 开启自动扫包 -->
<context:component-scan
  base-package="com.web">
  <!--制定扫包规则,不扫描@Controller注解的JAVA类,其他的还是要扫描 -->
  <context:exclude-filter type="annotation"
                          expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<!-- 开启自动扫包 -->
<context:component-scan
  base-package="com.web.*">
  <!--制定扫包规则,不扫描@Controller注解的JAVA类,其他的还是要扫描 -->
  <context:exclude-filter type="annotation"
                          expression="org.springframework.stereotype.Controller"/>
</context:component-scan>

image.png 修改后:

<!-- 开启自动扫包 -->
<context:component-scan
  base-package="com.web.controller">
  <!--制定扫包规则,不扫描@Controller注解的JAVA类,其他的还是要扫描 -->
  <context:exclude-filter type="annotation"
                          expression="org.springframework.stereotype.Controller"/>
</context:component-scan>

image.png