After upgrading my Struts2 application from version 2.5 to 6.4.0 and OGNL from 3.x to 3.3.4, I am encountering a NoSuchMethodException for an action method that is annotated. The application was working perfectly before the upgrade. Here are the details:
Context:
-
The init method in my IdentiteAction class is annotated as follows:
@Action(value = "/init", results = { @Result(name = "success", type = "redirect", location = "CamariWebConstantes.URL_IDENTITE"), @Result(name = "error", location = "error.jsp") }) public String init() throws WorkflowException, BackException, DisconnectedException, RedirectionException { // Method implementation }
-
I’m using the <s:url> tag to generate the URL for this action in my JSP:
<s:url var="identiteUrl" action="init" />
Issue:
After the upgrade, OGNL throws the following exception:
java.lang.NoSuchMethodException: fr.silicom.camari.web.action.navigation.IdentiteAction.init() at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1901) at ognl.ObjectMethodAccessor.callMethod(ObjectMethodAccessor.java:68) at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethodWithDebugInfo(XWorkMethodAccessor.java:98) at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethod(XWorkMethodAccessor.java:90) at ognl.OgnlRuntime.callMethod(OgnlRuntime.java:2034) at ognl.ASTMethod.getValueBody(ASTMethod.java:97) at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212) at ognl.SimpleNode.getValue(SimpleNode.java:258) at ognl.Ognl.getValue(Ognl.java:586)
What I’ve Tried:
-
Removed Annotations: I removed the annotations from the init method and configured the action directly in struts.xml. When doing this, the NoSuchMethodException disappeared, and OGNL could find and call the init method without any issues.
-
Changing Constants in struts.xml: I experimented with different constants and settings in struts.xml but did not find any solution that worked while keeping the annotations. (
-
Testing OGNL Versions: I tested various versions of OGNL to see if the issue was version-specific, but the problem persisted with each version I tried.
Questions:
-
Why might OGNL be unable to find the init method when it is annotated after upgrading to Struts2 6.4.0 and OGNL 3.3.4?
-
Are there any known changes or issues in how OGNL or Struts2 handles method resolution for annotated actions in these newer versions?
-
What steps can I take to troubleshoot and resolve this issue while using annotations?
Here’s m struts.xml configuration file for reference:
https://gist.github.com/matgouleau/b325e454064677772815a2150b59900f
Im using java 11, tomcat9, struts 6.4.0, ognl 3.3.4.
If you need more information I can give you some.
Mamat Sky is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.