我正在尝试使用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>