Non service builder generated services are not retrieved by ServiceLocator in freemarker template

Issue

  • By default, is not allowed to retrieve non-service builder generated services by ServiceLocator in freemarker template, getting this error:
    2022-08-25 08:30:38.427 WARN  [http-nio-8080-exec-10][ServiceLocator:42] Denied access to service "com.liferay.services.api.RegistredServicesApi" because it is not a Service Builder generated service
    2022-08-25 08:30:38.428 ERROR [http-nio-8080-exec-10][runtime:59] Error executing FreeMarker template
    freemarker.core.InvalidReferenceException: The following has evaluated to null or missing:
    ==> serviceLocator.findService("com.liferay.services.api.RegistredServicesApi")  [in template "20097#20123#43683" at line 10, column 100]
    
    ----
    Tip: If the failing expression is known to legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
    ----
    
    ----
    FTL stack trace ("~" means nesting-related):
    	- Failed at: userLocalService = serviceLocator.fin...  [in template "20097#20123#43683" at line 10, column 81]
    ----
    	at freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:134) ~[?:?]
    	at freemarker.core.Assignment.accept(Assignment.java:139) ~[?:?]
  • This change was done under LPS-134874 starting with DXP 7.4 GA1 adding the following configuration by default to true:
    template.engine.service.locator.restrict=true

Environment

  • DXP 7.4 GA1 or higher

Resolution

  • In order to allow all the generated services to be retrieved by ServiceLocator in freemarker template, you need to set this property inside your portal-ext.properties file:
    template.engine.service.locator.restrict=false
  • Restart the server in order to apply this new configuration, and test if after this change you are able to retrieve your services.
Was this article helpful?
0 out of 0 found this helpful