我想使用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)
但没有改变.