【发布时间】:2017-07-06 05:15:28
【问题描述】:
我想在 Spring 应用程序中使用 ManagedExecutorService。但是弹簧无法注入它。低于错误。
原因: org.springframework.beans.factory.NoSuchBeanDefinitionException: 否 符合条件的 bean 类型 [javax.enterprise.concurrent.ManagedExecutorService] 为 依赖项:预计至少有 1 个符合自动装配条件的 bean 这种依赖的候选人。依赖注解: {@javax.annotation.Resource(shareable=true,lookup=,name=, 描述=,身份验证类型=容器,类型=类 java.lang.Object, mappedName=)}
更新
我更新代码源代码如下注入ManagedExecutorService。
@Bean(name = "commonRestThreadExecutor")
public ManagedExecutorService commonRestThreadExecutor() throws NamingException {
return (ManagedExecutorService) new InitialContext().lookup("java:comp/DefaultManagedExecutorService");
}
@Autowired
private ManagedExecutorService commonRestThreadExecutor;
但现在我遇到了错误
引起:javax.naming.NameNotFoundException:名称> [DefaultManagedExecutorService] 未绑定在此上下文中。找不到 > [DefaultManagedExecutorService]。
【问题讨论】:
-
为了有资格进行注入,您的
ManagedExecutorService需要首先定义。你具体是怎么定义的?你是如何指代它来代替预期的注射的?请发布源代码。 -
@Gergely Bacso 我已经添加了代码