Struts 2的公约插件定义多个父包 [英] Struts 2 Convention Plugin Define Multiple Parent Packages

查看:582
本文介绍了Struts 2的公约插件定义多个父包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作Struts 2的Web应用程序,利用公约插件配置通过注释的一切。我打我的一些动作类,在这里我想使用多个父包的一个障碍。我发现这样做在 Apache的网站的手段 - 但这似乎是德precated。实在不行,扔回来类型不匹配:不能从转换的String [] 字符串错误

I'm working on Struts 2 web application, using the Convention Plugin to configure everything via annotations. I'm hitting a snag with some of my action classes, where I'd like to use multiple parent packages. I did find a means of doing it on Apache's site - but that appears to be deprecated. It does not work, throwing back a Type mismatch: cannot convert from String[] to String error.

@ParentPackage({"my-parent-package1, my-parent-package2"})
package com.mycompany.myapp.actions

import org.apache.struts2.config.ParentPackage;

我使用Struts 2.2.1。是否有可能通过注释授予的操作多个父包?似乎很奇怪,他们将不得不删除这是一个特点。

I am using Struts 2.2.1. Is it possible to grant an action multiple parent packages via annotations? Seems odd that they would have removed this as a feature.

推荐答案

您不能用注解做到这一点,但它仍然可以通过XML配置。该说的javadoc

You cannot do it with annotations, but it's still possible via XML config. The javadoc says

这个注释允许的行动来修改父包,他们
  正在使用。由于XWork的包是由公约插件创建
  经由Java包中存在的动作,有一定的技巧
  在XWork的包XWork的父包和命名空间的处理
  对发现​​的行动,以便在同一封装中两个动作就可以
  无碰撞指定不同的父母和命名空间。

This annotation allows actions to modify the parent package that they are using. Since XWork packages are created by the Convention plugin via the Java packages that the actions exist in, there is some tricky handling of XWork parent packages and namespaces of the XWork packages for discovered actions so that two actions in the same package can specify different parents and namespaces without collision.

为了正确地解决这个问题,XWork的包的名称
  该行动被放入使用这种格式建立的:

In order to handle this correctly, the name of the XWork package that actions are placed into is built using this format:

< Java的包>#<家长XWork的包>#<命名空间>

<java-package>#<parent-xwork-package>#<namespace>

这意味着,可能有多个父包在java包。但你不能将两个或多个 @ParentPackage 注释在同一类或包。正如你通知不能有父包阵列。但你至少可以有两个父包一个在包定义和其他的动作类。和不幸的配置生成器生成2 CONFIGS这个注解但动作配置只对具有一个注解之一创建。

This means that is possible to have multiple parent packages in the java package. But you cannot place two or more @ParentPackage annotations on the same class or package. And as you notices cannot have array for parent packages. But you can at least have two parent packages one at the package definition and other at the action class. And unfortunate the config builder builds two configs for this annotations but the action config is only created for the one that has an annotation.

这篇关于Struts 2的公约插件定义多个父包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆