我在liferay中有一个主题项目。我在 Liferay MySQL 数据库中创建了一个名为 colors 的新表。颜色表如下
实际上我有一个要求,一个特定的 css 文件应该根据状态为 true 的颜色表值加载到主题中,并且我的速度模板应该有点像如下所示
#set ($myColorService = $serviceLocator.findService("com.colors.themes.service.ColorLocalService"))
#set ($myColor = $myColorService.fetchActiveColor())
#if ($myColor == "blue")
<link href="$css_folder/themes/blue.css" rel="stylesheet" type="text/css"/>
#elseif ($myColor == "orange")
<link href="$css_folder/themes/orange.css" rel="stylesheet" type="text/css"/>
#else
<link href="$css_folder/themes/green.css" rel="stylesheet" type="text/css"/>
以下是我到目前为止所做的事情
我为颜色表创建了一个服务构建器项目 (theme_service-portlet)。service.xml如下所示
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.2.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_2_0.dtd"> <service-builder package-path="com.colors.themes"> <author>user</author> <namespace>theme</namespace> <entity name="Colors" local-service="true" remote-service="true"> <column name="colorId" type="long" primary="true" /> <column name="colorName" type="String" /> <column name="status" type="boolean" /> <finder return-type="Collection" name="Colors"> <finder-column name="status" /> </finder> </entity> </service-builder>
theme_service-portlet-service.jar
构建服务并在 lib 文件夹下生成jar ( )。- 复制
theme_service-portlet-service.jar
并放在liferay-portal-6.2-ce-ga2\tomcat-7.0.42\lib\ext
文件夹下。 - 在
portal_normal.vm
我使用了以下代码:
#set ($myColorService = $serviceLocator.findService("com.colors.themes.service.ColorLocalService")) #set ($myColor = $myColorService.fetchActiveColor()) #if ($myColor == "blue") <link href="$css_folder/themes/blue.css" rel="stylesheet" type="text/css"/> #elseif ($myColor == "orange") <link href="$css_folder/themes/orange.css" rel="stylesheet" type="text/css"/> #else <link href="$css_folder/themes/green.css" rel="stylesheet" type="text/css"/>
- 重启tomcat服务器
但我收到以下异常
04:44:55,896 ERROR [http-bio-8080-exec-3][ServiceLocator:39] com.liferay.portal.kernel.bean.BeanLocatorException: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'com.colors.themes.service.ColorLocalService' is defined
com.liferay.portal.kernel.bean.BeanLocatorException: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'com.colors.themes.service.ColorLocalService' is defined
at com.liferay.portal.bean.BeanLocatorImpl.locate(BeanLocatorImpl.java:122)
at com.liferay.portal.kernel.bean.PortalBeanLocatorUtil.locate(PortalBeanLocatorUtil.java:98)
at com.liferay.portal.template.ServiceLocator.findService(ServiceLocator.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.doInvoke(UberspectImpl.java:389)
at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:378)
at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:270)
at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:262)
at org.apache.velocity.runtime.parser.node.ASTReference.value(ASTReference.java:507)
at org.apache.velocity.runtime.parser.node.ASTExpression.value(ASTExpression.java:71)
at org.apache.velocity.runtime.parser.node.ASTSetDirective.render(ASTSetDirective.java:142)
at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:336)
at org.apache.velocity.Template.merge(Template.java:328)
谁能告诉我一些解决方案