相关疑难解决方法(0)

@Async不适合我

我正在使用@Scheduled,它一直工作正常,但无法让@Async工作.我测试了很多次,似乎它使我的方法异步.我还缺少其他任何东西,配置或参数吗?我有一个有两个方法的类,一个用@Scheduled标记的方法,执行并调用第二个用@Async标记的方法.

这是我的配置:

<!-- Scans within the base package of the application for @Components to configure as beans -->
<context:component-scan base-package="com.socialmeety" />
<context:annotation-config />
<tx:annotation-driven transaction-manager="transactionManager" />
<task:annotation-driven/>

<!-- Configures support for @Controllers -->
<mvc:annotation-driven />

<!-- Resolves view names to protected .jsp resources within the /WEB-INF/views directory -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/views/"/>
    <property name="suffix" value=".jsp"/>
</bean>

<dwr:configuration />
<dwr:annotation-config />
<dwr:url-mapping />
<dwr:controller id="dwrController" debug="true" />

<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
Run Code Online (Sandbox Code Playgroud)

谢谢.

java spring

12
推荐指数
1
解决办法
1万
查看次数

Spring中的@Async在Service类中不起作用?

当独立的Spring Boot应用程序@Asynch中带@Service注释的类中的方法不能异步运行时,我该怎么办?

当我运行它时,直接从工作中的主类(带@SpringBootApplication注释)直接使用相同的方法。例:

主班

    @SpringBootApplication
    @EnableAsync
    public class Application implements CommandLineRunner {

    @Override
    public void run(String... args) throws Exception {
// here when I call downloadAnSave() it runs asynchronously...
// but when I cal downloadAnSave() via downloadAllImages() it does not run asynchronously...
}

    }
Run Code Online (Sandbox Code Playgroud)

和我的服务类(这里的异步行为不起作用):

      @EnableAsync
        @Service
        public class ImageProcessorService implements IIMageProcessorService {

public void downloadAllImages(Run lastRun){
// this method calls downloadAnSave() in loop and should run asynchronously....
}

        @Async
        @Override
        public …
Run Code Online (Sandbox Code Playgroud)

java asynchronous spring-boot

2
推荐指数
1
解决办法
2166
查看次数

标签 统计

java ×2

asynchronous ×1

spring ×1

spring-boot ×1