Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么spring的@Async注释两次创建bean?_Spring - Fatal编程技术网

为什么spring的@Async注释两次创建bean?

为什么spring的@Async注释两次创建bean?,spring,Spring,我正在尝试使用Spring的@Async。然而,我注意到定义@Async的bean的构造函数被调用了两次 public class TestAsyncAnnotation { public TestAsyncAnnotation() { System.out.println("-----------con----------"); } @Async public void show() { System.out.println("

我正在尝试使用Spring的@Async。然而,我注意到定义@Async的bean的构造函数被调用了两次

public class TestAsyncAnnotation {

    public TestAsyncAnnotation() {
        System.out.println("-----------con----------");
    }
    @Async
    public void show() {
        System.out.println("From show method");
    }
}
配置

<?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:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/task
    http://www.springframework.org/schema/task/spring-task-3.0.xsd">

    <context:annotation-config/>
    <task:annotation-driven/>
    <bean name="testAsync" class="com.deva.mvc.testassync.TestAsyncAnnotation" />
</bean>


你能和我们分享这个bean的类定义吗?我已经用代码编辑了这篇文章。如果这是你仅有的Spring配置文件?是的。这是唯一的spring配置文件。