gpt4 book ai didi

jsf - org.jboss.weld.exceptions.WeldException : WELD-000049: Unable to invoke private void init()

转载 作者:行者123 更新时间:2023-12-03 23:56:52 27 4
gpt4 key购买 nike

由于某种原因,以下代码不起作用,我不明白为什么。我目前的,相当随意的,从大惊小怪的几个细微变化的信念是,因为 bean 是在 ExternalContext 之前创建的。它导致异常。但是,ExternalContext应该存在于这一点上,或者我相信。

我有一些解决方法的想法,例如在 LoginBean 中实例化 MessageProvider 类并发送到 MessagesBean 以供以后使用,但我更希望有一个接近以下格式的 session bean,而不是让它充当包装器.非常感谢您解释为什么会失败,以及可能的更正。

以下是主要关注的两个类:

登录 bean

@Named( value = "loginBean")
@RequestScoped
public class LoginBean {

private static final Logger LOG = Logger.getLogger(LoginBean.class.getName());

@Inject
private MessagesBean messagesBean;
@Inject
private LoginFormBean loginFormBean;
@Inject
private PersonBean personBean;
@Inject
private PersonFacade personFacade;

@NotNull
private String username;
@NotNull
private String password;

public LoginBean() {
}



/**
* Get the value of username
*
* @return the value of username
*/
public String getUsername() {
return username;
}

/**
* Set the value of username
*
* @param username new value of username
*/
public void setUsername(String username) {
this.username = username;
}

/**
* Get the value of password
*
* @return the value of password
*/
public String getPassword() {
return password;
}

/**
* Set the value of password
*
* @param password new value of password
*/
public void setPassword(String password) {
this.password = password;
}

public String login() {

Person person = personFacade.find(username);

if(person != null && person.getPasswordHash().equals(password)) {

personBean.setPerson(person);

return "success";
}
else {
messagesBean.setMessage(
loginFormBean.getUsernameInput().getClientId(),
"login.failed");

return "failure";
}
}

public String logout() {
return null;
}
}

消息 bean
@Named(value = "messagesBean")
@SessionScoped
public class MessagesBean implements Serializable {

private static final long serialVersionUID = 1L;

private FacesContext facesContext;
private Locale locale;
private ResourceBundle messageBundle;

/**
* Creates a new instance of MessagesBean
*/
public MessagesBean() {

}

@PostConstruct
private void init()
{
facesContext = FacesContext.getCurrentInstance();
locale = facesContext.getExternalContext().getRequestLocale();
messageBundle =
ResourceBundle.getBundle(
facesContext.getApplication().getMessageBundle(),
locale);


}

public void setMessage(String clientId, String messageKey)
{
FacesMessage facesMessage =
new FacesMessage(messageBundle.getString(messageKey));

facesContext.addMessage(clientId, facesMessage);
}
}

下面是上述类发生的错误的堆栈跟踪:
javax.faces.el.EvaluationException: org.jboss.weld.exceptions.WeldException: WELD-000049: Unable to invoke private void com.healthdataviews.healthdataviewstrial.support.MessagesBean.init() on com.healthdataviews.healthdataviewstrial.support.MessagesBean@1126aa67
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.jboss.weld.exceptions.WeldException: WELD-000049: Unable to invoke private void com.healthdataviews.healthdataviewstrial.support.MessagesBean.init() on com.healthdataviews.healthdataviewstrial.support.MessagesBean@1126aa67
at org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.invokeMethods(DefaultLifecycleCallbackInvoker.java:100)
at org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.postConstruct(DefaultLifecycleCallbackInvoker.java:81)
at org.jboss.weld.injection.producer.BasicInjectionTarget.postConstruct(BasicInjectionTarget.java:126)
at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:162)
at org.jboss.weld.util.bean.IsolatedForwardingBean.create(IsolatedForwardingBean.java:45)
at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:96)
at org.jboss.weld.context.PassivatingContextWrapper$AbstractPassivatingContextWrapper.get(PassivatingContextWrapper.java:76)
at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:101)
at org.jboss.weld.bean.ContextualInstanceStrategy$CachingContextualInstanceStrategy.get(ContextualInstanceStrategy.java:178)
at org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50)
at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:99)
at org.jboss.weld.bean.proxy.ProxyMethodHandler.getInstance(ProxyMethodHandler.java:125)
at com.healthdataviews.healthdataviewstrial.support.MessagesBean$Proxy$_$$_WeldClientProxy.setMessage(Unknown Source)
at com.healthdataviews.healthdataviewstrial.controller.ejb.LoginBean.login(LoginBean.java:100)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.sun.el.parser.AstValue.invoke(AstValue.java:289)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
... 36 more

更新

我确切地发现了错误发生的位置。当我调用 getMessageBundle , 我收到了 NullPointerException导致 ResourceBundle.getBundle()搜索导致它在 @PostConstruct init() 上崩溃的空包.新问题:如何将我的 Messages.properties 链接到 getMessageBundle()打电话,或者我应该把它翻译成 getResourceBundle("bundle") ?

更新

我通过设置 <message-bundle> 让它工作了在我的 faces-config.xml 中。除了将其声明为 <resource-bundle> 之外,还有什么方法可以在不加载每个 .xhtml 文件的情况下包含它?也?

最佳答案

请查看不等于 null @Postconstruct 中的 messageBundle 语句方法。

IE。,

if(messageBundle != null)
messageBundle = ResourceBundle.getBundle(
facesContext.getApplication().getMessageBundle(),
locale);

关于jsf - org.jboss.weld.exceptions.WeldException : WELD-000049: Unable to invoke private void init(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39428161/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com