因为struts2 2.3.15.1版本存在bug,需要升级至struts2 2.3.16.1版本,测试时候,却发现功能报错。
动态方法调用失败,找不到对应的action映射。
能够肯定的是代码本身没有问题,于是查找配置文件,猜测是不同版本的某些全局变量的默认值不同。
果然不出所料,struts2-core-2.3.15.1是以下配置
### Set this to false if you wish to disable implicit dynamic method invocation
### via the URL request. This includes URLs like foo!bar.action, as well as params
### like method:bar (but not action:foo).
### An alternative to implicit dynamic method invocation is to use wildcard
### mappings, such as <action name="*/*" method="{2}" class="actions.{1}">
struts.enable.DynamicMethodInvocation = true
struts2-core-2.3.16.1是以下配置
### Set this to false if you wish to disable implicit dynamic method invocation
### via the URL request. This includes URLs like foo!bar.action, as well as params
### like method:bar (but not action:foo).
### An alternative to implicit dynamic method invocation is to use wildcard
### mappings, such as <action name="*/*" method="{2}" class="actions.{1}">
struts.enable.DynamicMethodInvocation = false
需要修改全局参数,以支持动态方法调用。
后续思考:
由此也说明,动态方法调用在将来的某个版本中,有可能会被废弃。
建议新项目不要启用动态方法调用,而使用通配符来实现类似功能。