繁体   English   中英

Liferay配置操作类-Spring依赖注入

[英]Liferay Configuration Action Class - Spring dependency Injection

在Liferay中,配置操作类在liferay-portlet.xml中定义。问题是,如果我使用任何spring依赖项注入,那么它将无法正常工作。

<portlet>
    <portlet-name>search</portlet-name>
    <icon>/icon.png</icon>
    <configuration-action-class>com.mypack.MyConfigurationAction</configuration-action-class>
    <header-portlet-css>/css/main.css</header-portlet-css>
    <footer-portlet-javascript>/js/main.js</footer-portlet-javascript>
    <css-class-wrapper>search-portlet</css-class-wrapper>
    <add-default-resource>true</add-default-resource>
</portlet>

动作类的实现

public class MyConfigurationAction extends DefaultConfigurationAction {

    private @Value("${test.property1}") String property1;
    private @Value("${test.property2}") String property2;
}

我如何将这些属性注入此Action类,而不在类中使用ClassPathXmlApplicationContext和硬编码spring.xml文件

在portlet开发中有两种保存首选项的方法(在liferay中),

  1. 通过liferay的特定方式,它使用liferay-portlet.xml条目。 春天无法管理。

  2. JSR-286 [portal agnostic],portlet编辑模式。

在使用Spring MVC框架开发portlet时,建议使用portlet EDIT模式。

在Spring MVC Portlet框架中,您可以按Portlet模式映射Portlet请求。

例如:创建如下的控制器类,它将映射到EDIT模式的请求。

@Controller
@RequestMapping("EDIT")
public class PreferencesController

有两种方法,一种带有注释@RenderMapping的方法负责视图,另一种带有注释@ ActionMapping / @ RequestMapping的方法负责存储首选项。

希望这会有所帮助。

尝试这个

portlet.xml

<supports>
.....
<portlet-mode>edit</portlet-mode>
</supports>

控制器类

@Controller
@RequestMapping(value = "EDIT")
 public class XYZ{
}

HTH

首先,“配置”不是“编辑”模式。 如果启用“编辑”模式(如其他人所建议),您将在portlet菜单中获得“首选项”按钮。 这是一项Liferay功能,您可以根据需要进行覆盖。

我自己还没有尝试过,但是您可以尝试使用@Autowired来自动连接MyConfigurationAction类(如果需要,可以使用@Required注释?)。 不要忘记将<context:annotation-config/>放入applicationContext.xml文件中(如果尚未完成的话)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM