我正在使用 Spring 3.2.2.RELEASE 版本。@Async 注释没有按预期工作。
应用程序上下文.xml
<?xml version="1.0" encoding="windows-1252"?>
<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:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
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/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- Enable AspectJ style of Spring AOP -->
<aop:aspectj-autoproxy proxy-target-class="true"/>
<context:component-scan base-package="com.pratik" />
<tx:annotation-driven />
导入.java
public String async() {
final String asssetImportId = ObjectId.get().toHexString();
process.asyncTest();
logger.info("Ongoing");
return asssetImportId;
}
进程.java
@Async
public void asyncTest() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
logger.info("After Sleep");
}
After Sleep日志应最后打印,但在继续之前打印