[英]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中),
通過liferay的特定方式,它使用liferay-portlet.xml條目。 春天無法管理。
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.