为什么spring的@Async注释两次创建bean?
我正在尝试使用Spring的@Async。然而,我注意到定义@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("
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配置文件。