Java 在 Struts 1.1 中抛出“No bean specified Error”的可能原因是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2775345/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 12:43:34  来源:igfitidea点击:

What are the possible causes for throwing a "No bean specified Error" in Struts 1.1?

javastruts

提问by Ruepen

What would be some of the possible causes for throwing this error running Struts 1.1 in a web app? The stacktrace from my IDE console window is shown below:

在 Web 应用程序中运行 Struts 1.1 时引发此错误的一些可能原因是什么?我的 IDE 控制台窗口中的堆栈跟踪如下所示:

java.lang.IllegalArgumentException: No bean specified
at org.apache.commons.beanutils.PropertyUtils.getPropertyDescriptor(PropertyUtils.java:837)
at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:934)
at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:808)
at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1252)
at org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:821)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:254)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:223)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:283)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3245)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2003)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:1909)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1359)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)

回答by Ruepen

This is most likely thrown by the org.apache.commons.beanutils.PropertyUtilsclass trying to access properties from a bean which is null. Your ActionFormmight be that bean.

这很可能是由org.apache.commons.beanutils.PropertyUtils试图从空 bean 访问属性的类抛出的。你ActionForm可能就是那个豆子。

Do you have an ActionFormdefined for your Action? Check your struts-config.xmlfile and see if the name attribute of the <action>tag references a <form-bean>.

你有ActionForm定义Action吗?检查您的struts-config.xml文件,看看<action>标签的 name 属性是否引用了<form-bean>.

You are not providing enough information here, so I can only guess. You should post the stacktrace too.

你在这里没有提供足够的信息,所以我只能猜测。您也应该发布堆栈跟踪。

EDIT:There is one other thing you could check for. From the stacktrace it seems your Action form is OK (I don't think you would have gotten so deep in the call if the form was null) but it might be something on the form.

编辑:还有一件事你可以检查。从堆栈跟踪来看,您的 Action 表单似乎没问题(如果表单为空,我认为您不会在调用中如此深入)但它可能是表单上的某些内容。

Are you using nested properties or setting something on a bean on the form, a case like :

您是使用嵌套属性还是在表单上的 bean 上设置某些内容,例如:

public class MyAction extends ActionForm {
  private SomeBean innerBean;
  ...
  public SomeBean getInnerBean() { 
    return this.innerBean; 
  }
}

If in your JSP you specified form.innerBean.somePropertywhen you submit a value for this, Struts will try to do something like a form.getInnerBean().setSomeProperty(...). If the part form.getInnerBean()is null, Struts will complain before you get NullPointerException.

如果在您的 JSP 中指定了form.innerBean.someProperty当您为此提交值时,Struts 将尝试执行类似form.getInnerBean().setSomeProperty(...). 如果该部分form.getInnerBean()为空,Struts 将在您获得 NullPointerException 之前抱怨。

A solution for this kind of things is to change:

这种事情的解决方案是改变:

public class MyAction extends ActionForm {
  private SomeBean innerBean;
  ...
}

to

public class MyAction extends ActionForm {
  private SomeBean innerBean = new SomeBean();
  ...
}

Might this be the cause?

这可能是原因吗?

回答by Tomás

Hi I used to have same problem or similar. In my case I defined the Form and initialized his properties. but when I submit the form I had same error, the message said that one of mi fields are null. That was because in my struts-config.xml I used to have scope="request" indeed of scope="session". That way every time I submit I lose my data.

嗨,我曾经有同样的问题或类似的问题。在我的例子中,我定义了 Form 并初始化了他的属性。但是当我提交表单时,我遇到了同样的错误,消息说 mi 字段之一为空。那是因为在我的 struts-config.xml 中,我曾经有 scope="request" 确实是 scope="session"。这样每次提交时我都会丢失数据。