I am currently working on the Liferay 7.1.2.ga3 CE with tomcat and was going over the OSGI section of the tutorial in the official documentation. This one: Docs
I decided to give it a shot with the simplest project possible. I have created a Liferay Workspace in my IntelliJ idea and added some component as discribed in the turorial.
The problem is that it either does not inject or does inject but does not retrieve the dependecy because in this case in the consumer the _applicationServices variable is always at null.
EDIT: I have asked the same question in the official Liferay forum here : Question in Liferay.org
Here is the code:
The api:
@ProviderType
public interface ApplicationServices {
String getSearchFiltersForRegister(String registerCode);
}
The provider:
@Component(
immediate = true,
property = {
},
service = ApplicationServices.class
)
public class ApplicationServicesImpl implements ApplicationServices {
@Override
public String getSearchFiltersForRegister(String registerCode) {
return "OSGI modularity made service";
}
}
The consumer:
@ManagedBean(name = "registerSearchBean")
@ViewScoped
@Component(
immediate = true,
property = {
"osgi.command.scope=getSearchFiltersForRegister",
"osgi.command.function=getSearchFiltersForRegister"
},
service = Object.class
)
public class RegisterSearchBean {
public String message;
@Reference
private ApplicationServices _applicationServices;
@PostConstruct
public void initBean(){
getSearchFiltersForRegister();
}
public void getSearchFiltersForRegister(){
ApplicationServices applicationServices=_applicationServices;
message=applicationServices.getSearchFiltersForRegister("asd");
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
NOTE: I have also tried to separate the consumre module in a different class and use it in this bean without success.
Additional info:
- The project is a gradle LiferayWorkaspace.
- Api and services modules are generated via the Liferay plugin in the modules folder.
- The JSF module is generated via the maven archetype with gradle support in the "war" folder.
- Dependecies are correctly defined and it is all correctly deployed in the Liferay Server. At least it appears so.... no errors for missing classes appear on deploy.
What am I doing wrong and why application services is always null?