小编Hoa*_*ran的帖子

注入返回String CDI的生产者方法

我想使用CDI向JSF Web应用程序中的托管bean注入常量字符串消息,这里是生产者类:

@Named
@RequestScoped
public class StringProducer {

   @Produces
   @Named("message")    
   @RequestScoped
   public String getMessage() {
      return "Hello World";
   }
}
Run Code Online (Sandbox Code Playgroud)

以下是它如何在另一个托管bean中注入:

@Inject Named("message") String message;
Run Code Online (Sandbox Code Playgroud)

但这总是导致异常:

org.jboss.weld.exceptions.UnproxyableResolutionException: WELD-001435 Normal scoped bean int is not proxyable
Run Code Online (Sandbox Code Playgroud)

我试图在Instance中包装String类型,如下所示:

@Inject Named("message") Instance<String> message;
Run Code Online (Sandbox Code Playgroud)

但没有改变.

java-ee cdi weld

9
推荐指数
2
解决办法
2512
查看次数

标签 统计

cdi ×1

java-ee ×1

weld ×1