Spring异步@Async

1.spring配置文件中加注解

<!-- 支持异步方法执行 -->
<task:annotation-driven />

命名空间同时也加上:web

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:task="http://www.springframework.org/schema/task"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context.xsd
            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
            http://www.springframework.org/schema/task
            http://www.springframework.org/schema/task/spring-task-4.0.xsd">

    <context:component-scan base-package="cn.whbing.pro.web"/>
    <mvc:annotation-driven enable-matrix-variables="true" />
    <!-- 支持异步方法执行 -->
    <task:annotation-driven />

    <context:property-placeholder location="classpath:config/*.properties" />
    <import resource="/spring/spring-config-dao.xml"/>

</beans>

注意spring

Spring事务<tx:annotation-driven/>不要混淆。spring-mvc