在我工作的Scala项目中,我们有一个API,可以在早期导入像这样的全局执行上下文
import scala.concurrent.ExecutionContext.Implicits.global
我稍后创建一个需要执行上下文的UserStorageService。我试图在我的应用程序中引入Spring Annotations,但我却陷入了如何处理执行上下文的问题。如何自动装配隐式变量?我试过这个
class UserStorageService(
@Qualifier("userdb") val databaseConnector: DatabaseConnector
)(implicit executionContext: ExecutionContext) extends UserStorageTable {
我试图获得
private val userStorageService = appContext.getBean(classOf[UserStorageService])
导致
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type 'scala.concurrent.ExecutionContext' available:
expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
答案 0 :(得分:0)
导入此:
import scala.concurrent.ExecutionContext;
import scala.concurrent.ExecutionContext$;
并在您的配置(@Configuration
)中添加
@Bean
public ExecutionContext getExecutionContext() {
return ExecutionContext$.MODULE$.global();
}
然后ExecutionContext
bean将被添加到Spring上下文中。