MyFramework - struts2 零配置:convention

为了使用convention插件,需要将struts2项目下的struts2-convention-plugin-2.1.6.jar 文件复制到struts2应用的WEB-INF\lib目录下。
对于convention 而言,它会自动搜索位于 action,actions,struts,struts2包下的所有java类,convention插件会把如下2种java类当成Action处理:
(1)所有实现了com.opensymphony.xwork2.Action的java类
(2)所有类名以Action结尾的java类



<constant name="struts.ui.theme" value="simple" />
<constant name="struts.devMode" value="true" />
<constant name="struts.i18n.reload" value="true" />
<constant name="struts.configuration.xml.reload" value="true" />
<constant name="struts.convention.classes.reload" value="true" />
<constant name="struts.i18n.encoding" value="UTF-8" />
<constant name="struts.custom.i18n.resources" value="message" />
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<constant name="struts.action.extension" value="action,do,ajax" />
<constant name="struts.convention.result.path" value="/page/" />
<constant name="struts.convention.action.mapAllMatches" value="true" />
<constant name="struts.convention.action.suffix" value="Action" />
<constant name="struts.convention.action.name.lowercase" value="true" />
<constant name="struts.convention.action.name.separator" value="" />
<constant name="struts.convention.default.parent.package" value="default" />
<constant name="struts.convention.action.disableScanning" value="false" />
<constant name="struts.convention.package.locators" value="action,front,back" />
<constant name="struts.convention.package.locators.disable" value="flase" />
<constant name="struts.convention.package.locators.basePackage" value="" />
<constant name="struts.convention.action.eagerLoading" value="true" />

<constant name="struts.multipart.maxSize" value="1000000000" />
<constant name="struts.serve.static.browserCache" value="false" />
<constant name="struts.serve.static" value="true" />
<constant name="struts.objectFactory.spring.autoWire.alwaysRespect" value="true" />



<constant name="struts.convention.result.path" value="/page/" />
设置convention插件定位视图资源的根路径,默认是/WEB-INF/content
<constant name="struts.convention.action.mapAllMatches" value="true" /> 设置即使没有@Action注解,依然创建Action映射,默认值为false
<constant name="struts.convention.action.suffix" value="Action" />
convention搜索Action类的类名后缀,默认为Action
<constant name="struts.convention.action.name.lowercase" value="true" /> 设置映射Action时,是否将Action的name属性值转为小写字母,默认为true
<constant name="struts.convention.action.name.separator" value="" /> 设置映射Action时,指定Action的name属性时,各单词之间的分隔符,默认为中划线
<constant name="struts.convention.default.parent.package" value="default" />
<constant name="struts.convention.action.disableScanning" value="false" />
<constant name="struts.convention.package.locators" value="action,front,back" />
convention 插件使用改常量指定的包作为搜寻Action的根包,
默认为:action,actions,struts,struts2
<constant name="struts.convention.package.locators.disable" value="flase" />
<constant name="struts.convention.package.locators.basePackage" value="" />
<constant name="struts.convention.action.eagerLoading" value="true" />



struts动态访问,在包action中新建一个TestAction类,方法index,即可进行动态访问。
http://localhost:8080/demo/test!index.do
需要设置<constant name="struts.convention.action.mapAllMatches" value="true" />,否则会出现异常:
There is no Action mapped for namespace [/] and action name [test!index] associated with context path [/lijietest]. - [unknown location]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值