简体   繁体   English

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

[英]Liferay Configuration Action Class - Spring dependency Injection

In Liferay, the Configuration Action class is defined in liferay-portlet.xml The problem is, if I use any spring dependency injection, it's not working. 在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>

Action Class implementation 动作类的实现

public class MyConfigurationAction extends DefaultConfigurationAction {

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

How do I inject these properties into this Action class, without using ClassPathXmlApplicationContext and hard coding spring.xml file in the class 我如何将这些属性注入此Action类,而不在类中使用ClassPathXmlApplicationContext和硬编码spring.xml文件

There are two ways to save preferences in portlet development[in liferay], 在portlet开发中有两种保存首选项的方法(在liferay中),

  1. Through liferay specific way, which uses liferay-portlet.xml entry . 通过liferay的特定方式,它使用liferay-portlet.xml条目。 cant be managed with spring. 春天无法管理。

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

While developing portlet with Spring MVC framework, its advisable to use portlet EDIT mode. 在使用Spring MVC框架开发portlet时,建议使用portlet EDIT模式。

In Spring MVC portlet framework, you can map portlet requests by portlet mode. 在Spring MVC Portlet框架中,您可以按Portlet模式映射Portlet请求。

For Example: Create controller class as below which will map to EDIT mode requests. 例如:创建如下的控制器类,它将映射到EDIT模式的请求。

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

with two methods, one method with annotation @RenderMapping, responsible for view and other method with annotation @ActionMapping/@RequestMapping responsible for storing preferences. 有两种方法,一种带有注释@RenderMapping的方法负责视图,另一种带有注释@ ActionMapping / @ RequestMapping的方法负责存储首选项。

Hope this would help. 希望这会有所帮助。

Try this 尝试这个

portlet.xml

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

Controller class 控制器类

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

HTH HTH

First of all, "Configuration" is NOT "Edit" mode. 首先,“配置”不是“编辑”模式。 If you enable Edit mode (as suggested by others), you'll get "Preferences" button in your portlet menu. 如果启用“编辑”模式(如其他人所建议),您将在portlet菜单中获得“首选项”按钮。 It is a Liferay feature that you can override as per your requirement. 这是一项Liferay功能,您可以根据需要进行覆盖。

I have Not tried this myself but you can try to use @Autowired to AutoWire your MyConfigurationAction class (and possibly use @Required annotation if needed?). 我自己还没有尝试过,但是您可以尝试使用@Autowired来自动连接MyConfigurationAction类(如果需要,可以使用@Required注释?)。 Don't forget to put <context:annotation-config/> in your applicationContext.xml file, if not already done. 不要忘记将<context:annotation-config/>放入applicationContext.xml文件中(如果尚未完成的话)。

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

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