主题中的 Liferay 访问数据库表:未定义名为“com.colors.themes.service.ColorLocalService"的 bean [英] Liferay access DB table in theme: No bean named 'com.colors.themes.service.ColorLocalService' is defined

查看:22
本文介绍了主题中的 Liferay 访问数据库表:未定义名为“com.colors.themes.service.ColorLocalService"的 bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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"/>#别的<link href="$css_folder/themes/green.css" rel="stylesheet" type="text/css"/>

以下是我目前所做的事情

  • 我为 colors 表创建了一个服务构建器项目 (theme_service-portlet).这service.xml 如下所示

  • 构建服务并在lib文件夹下生成jar(theme_service-portlet-service.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"/>#别的<link href="$css_folder/themes/green.css" rel="stylesheet" type="text/css"/>

  • 重启tomcat服务器

但我收到以下异常

04:44:55,896 错误 [http-bio-8080-exec-3][ServiceLocator:39] com.liferay.portal.kernel.bean.BeanLocatorException: org.springframework.beans.factory.NoSuchBeanDefinitionException:未定义名为com.colors.themes.service.ColorLocalService"的 beancom.liferay.portal.kernel.bean.BeanLocatorException:org.springframework.beans.factory.NoSuchBeanDefinitionException:没有定义名为com.colors.themes.service.ColorLocalService"的bean在 com.liferay.portal.bean.BeanLocatorImpl.locate(BeanLocatorImpl.java:122)在 com.liferay.portal.kernel.bean.PortalBeanLocatorUtil.locate(PortalBeanLocatorUtil.java:98)在 com.liferay.portal.template.ServiceLocator.findService(ServiceLocator.java:36)在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)在 java.lang.reflect.Method.invoke(Method.java:606)在 org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.doInvoke(UberspectImpl.java:389)在 org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:378)在 org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:270)在 org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:262)在 org.apache.velocity.runtime.parser.node.ASTReference.value(ASTReference.java:507)在 org.apache.velocity.runtime.parser.node.ASTExpression.value(ASTExpression.java:71)在 org.apache.velocity.runtime.parser.node.ASTSetDirective.render(ASTSetDirective.java:142)在 org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:336)在 org.apache.velocity.Template.merge(Template.java:328)

谁能告诉我一些解决方案

解决方案

首先,您有暴露数据访问层的 ServiceBuilder 层;这部分很好.

您的主题代码基本正确.您应该使用 ServiceLocator 来查找您的服务,但是您缺少提供服务的 servlet 上下文.例如,如果提供服务的插件在 color-service-portlet.war 中,那么服务定位器调用将如下所示:

 #set ($myColorService = $serviceLocator.findService("color-service-portlet", "com.colors.themes.service.ColorLocalService"))

您看到的异常是因为您正在使用门户的表单来查找门户服务,但门户当然没有导出该服务,因此您会收到 BeanLocatorException.

I have a theme project in liferay. I have created a new table called colors in my liferay MySQL database. The colors table is given below

Actually I have a requirement that a particular css file should be loaded in theme based on the color table value whose status is true and my velocity template should be somewhat like as shown below

#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"/>

The following things are somethings which I have done so far

  • I have created a service builder project (theme_service-portlet) for the colors table. The service.xml is shown below

    <?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>

  • Builded the service and jar (theme_service-portlet-service.jar) is generated under lib folder.

  • Copy the theme_service-portlet-service.jar and placed under liferay-portal-6.2-ce-ga2\tomcat-7.0.42\lib\extfolder.
  • In portal_normal.vm I have used the following code:

#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"/>

  • Restarted the tomcat server

But I am getting the following exception

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)

Can anyone please tell me some solution for this

解决方案

First of all you have the ServiceBuilder layer that exposes your data access layer; this part is good.

Your code for the theme is mostly right. You should be using ServiceLocator to find your service, but you're missing the servlet context that is providing the service. For example, if the plugin providing the service is in color-service-portlet.war, then the service locator call will look like:

    #set ($myColorService = $serviceLocator.findService("color-service-portlet", "com.colors.themes.service.ColorLocalService"))

The exception that you're seeing is because you are using the portal's form to find a portal service but of course the portal is not exporting that service, so you get the BeanLocatorException.

这篇关于主题中的 Liferay 访问数据库表:未定义名为“com.colors.themes.service.ColorLocalService"的 bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆