Calling Non-OSGi Code that Uses OSGi Services

Liferay DXP’s static service utilities (e.g., UserServiceUtil, CompanyServiceUtil, GroupServiceUtil, etc.) are examples of non-OSGi code that use OSGi services. Service Builder generates them for backwards compatibility purposes only. If you’re tempted to call a *ServiceUtil class or your existing code calls one, access the *Service directly instead using one these alternatives:

  • If your class is a Declarative Services component, use an @Reference annotation to access the *Service class.

  • If your class isn’t a Declarative Services component, use a ServiceTracker to access the *Service class.

You can check the state of Liferay DXP’s services in the Gogo shell. The scr:list Gogo shell command shows all Declarative Services components, including inactive ones from unsatisfied dependencies. To find unsatisfied dependencies for Service Builder services, use the Dependency Manager’s dependencymanager:dm wtf command. Note that these commands only show components that haven’t been activated because of unsatisfied dependencies. They don’t show pure service trackers that are waiting for a service because of unsatisfied dependencies.

Detecting Unresolved OSGi Components

Felix Gogo Shell

« Resolving Bundle-SymbolicName Syntax IssuesConnecting to JNDI Data Sources »
0 人中有 0 人觉得有帮助