I have an application that contains an API Rest implemented as a Spring Boot application (1.5.18.RELEASE version)
This API contains a controller that executes a service method asynchronous. The method is marked with @Async
annotation
The @EnableAsync
annotation is set on my configuration class.
When i execute the application like a typical Spring Boot application, the method is executed asynchronous. if i generate a war (using maven) and this war is deployed on JBoss (6.4 Version), the same service is executed synchronous.
Could someone explain me this behavior? Should i add any type of configuration?
The source code is below:
The Spring Boot configuration
@SpringBootApplication
@EnableCustomConfiguration
@EnableCaching
@EnableScheduling
public class WebApplication {
public static void main(String[] args) {
SpringApplication.run(WebApplication.class, args);
}
}
My custom annotation:
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Import({CustomServicesConfiguration.class})
@Documented
public @interface EnableCustomConfiguration {
}
My configuration class:
@Configuration
@ComponentScan("com.bs.custom.api")
@EntityScan(basePackages = "com.bs.custom.api.domain", basePackageClasses = Jsr310JpaConverters.class)
@EnableJpaRepositories(basePackages = "com.bs.custom.api.repository")
@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true)
@EnableAsync
public class CustomServicesConfiguration {
static {
SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL);
}
}
I've modified my WebApplication class to extends from SpringBootServletInitializer, as is defined on Spring Boot reference guide (thanks M.Deinum)
The final WebApplication class source code is below:
@SpringBootApplication
@EnableCustomConfiguration
@EnableCaching
@EnableScheduling
@EnableAsync
public class WebApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(WebApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(WebApplication.class);
}
}
Now, asynchronous methods run correctly on JBoss