extとservicebuilderを使用せずに再利用可能なカスタムサービスを実装しようとしています。私はこの記事を参照しました:http ://www.devatwork.nl/2010/04/implementing-a-reusable-liferay-service-without-ext-or-service-builder/ 、しかし私はこれをどのように実装すべきか混乱しています日食を使用していますか?これを行うために私が従った手順は次のとおりです。
- Created liferay-plugin project within eclipse.
- Created package containing CustomServices (interface) and CustomServicesUtil.
- Created jar file of package in step 2.
- Placed that jar file in tomcat\lib\ext\
- Then created package (with in same liferay-plugin project), that includes CutomServicesImpl and CustomServicesBaseImpl
- Defined portlet-spring.xml, service.properties, and modified web.xml (as per the article), and finally deployed the project.
デプロイ時に、プロジェクトは正常にデプロイされますが、CustomServicesUtil.getCustomMethod()を介してCustomServicesImplで定義されたcustomMethodsを使用しようとすると、次のエラーが発生します。
"java.lang.ClassNotFoundException: com.demo.custom.services.CustomServicesUtil"
customservices.jarファイルを含めるようにビルドパスを構成しましたが、機能せず、同じエラーが表示されます。これが再利用可能なサービスを実装する正しい方法であるかどうかはわかりません。プロジェクトの1つでカスタムメソッドを使用できるように、これを試しました。
カスタムサービスのコードは次のとおりです。
CustomServices.java
package com.demo.custom.services; import com.liferay.portal.model.User; public interface CustomServices { String getCustomName(User user); }
CustomServicesUtil.java
package com.demo.custom.services; import com.liferay.portal.model.User; public class CustomServicesUtil { private static CustomServices services; public static CustomServices getServices() { if (services == null) { throw new RuntimeException("Custom Services not set"); } return services; } public void setServices(CustomServices pServices) { services = pServices; } public static String getCustomName(User user){ return getServices().getCustomName(user); } }
CustomServicesBaseImpl.java
package com.demo.custom.services.impl; import com.demo.custom.services.CustomServices; import com.liferay.portal.kernel.exception.SystemException; import com.liferay.portal.service.base.PrincipalBean; import com.liferay.portal.util.PortalUtil; public abstract class CustomServicesBaseImpl extends PrincipalBean implements CustomServices { protected CustomServices services; public CustomServices getServices() { return services; } public void setServices(CustomServices pServices) { this.services = pServices; } protected void runSQL(String sql) throws SystemException { try { PortalUtil.runSQL(sql); } catch (Exception e) { throw new SystemException(e); } } }
CustomServicesImpl.java
package com.demo.custom.services.impl; import com.liferay.portal.model.User; public class CustomServicesImpl extends CustomServicesBaseImpl { @Override public String getCustomName(User user) { // TODO Auto-generated method stub if(user == null){ return null; }else{ return new StringBuffer().append(user.getFirstName()).append(" ").append(user.getLastName()).toString(); } } }
これは、このサービスを利用している別のポートレットのコントローラークラスのコードです。
HelloCustomName.java
package com.test; import java.io.IOException; import javax.portlet.PortletException; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; import com.demo.custom.services.CustomServicesUtil; import com.liferay.portal.kernel.util.WebKeys; import com.liferay.portal.model.User; import com.liferay.portal.theme.ThemeDisplay; import com.liferay.util.bridges.mvc.MVCPortlet; public class HelloCustomName extends MVCPortlet { @Override public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException { System.out.println("--doview----"); ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(WebKeys.THEME_DISPLAY); User user = themeDisplay.getUser(); String customName = CustomServicesUtil.getCustomName(user); //getting error here System.out.println("customName:" + customName); } }
再利用可能なサービスを実装する方法を教えてください。どんなガイダンスも本当に役に立ちます。
ありがとう。