RE: How to use AopService in my FooLocalServiceImpl or FooServiceImpl class

thumbnail
Nader Jafari, modified 5 Years ago. Junior Member Posts: 84 Join Date: 8/24/11 Recent Posts
Hi guys
I wanna use AopService in my LocalServiceImpl and ServiceImpl classes in a service-builder module in Liferay 7.2.1 GA2
So i added bellow @Component to my FooLocalServiceImp class.
@Component(
    property = "model.class.name=com.liferay.sample.model.Foo",
    service = AopService.class
)
Then i just run buildService gradle task
Next when i ran delpoy task i faced bellow error  in my console:

error  : Class com.liferay.sample.service.impl.FooLocalServiceImpl is not assignable to specified service com.liferay.portal.aop.AopService

Then i googled about this and drill to Liferay source So understand i should implement  AopService in the FooLocalServiceBaseImpl abstract class and override two functions as bellow :
    @Override
&nbsp;&nbsp;&nbsp; public Class<!--?-->[] getAopInterfaces() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return new Class<!--?-->[] {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FooLocalService.class, IdentifiableOSGiService.class,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PersistedModelLocalService.class
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };
&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; @Override
&nbsp;&nbsp;&nbsp; public void setAopProxy(Object aopProxy) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fooLocalService = (FooLocalService)aopProxy;
&nbsp;&nbsp;&nbsp; }


But FooLocalServiceBaseImpl regenerated on every build-service!
is there any way to prevent this?
thumbnail
David H Nebinger, modified 5 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts
There is just so much wrong here, but let's start with the major issue...

You should not modify generated sources. Period. And FooLocalServiceBaseImpl is generated and therefore not to be monkeyed with. All of your code goes to FooLocalServiceImpl, period.

Outside of that, you shouldn't force a class to become another type of service. FooLocalServiceBaseImpl already implements what it should, including AopService. Why you are trying to have it re-implement it again is unclear.

So I don't know where you got your marching orders on what to do or why, but they are mostly just plain wrong.
thumbnail
Nader Jafari, modified 5 Years ago. Junior Member Posts: 84 Join Date: 8/24/11 Recent Posts
Hi David

I just want to implement a simple tetsIntegration module that explained here :

https://liferay.dev/forums/-/message_boards/message/119429731

But there aren't any Document for that.

I saw some example in the GitHub and i think it's necessary if i want to use LocalService/Service in my Test classes , it should have :
@Component(
    property = "model.class.name=com.liferay.sample.model.Foo",
    service = AopService.class
)



Here is my project in GitHub :

https://github.com/naderjafari/liferay-todo-list/tree/Liferay-7.2.1-fix-test

My test class :

https://github.com/naderjafari/liferay-todo-list/blob/Liferay-7.2.1-fix-test/liferay-todo-list-test/src/testIntegration/java/com/chberndt/liferay/todo/list/service/persistence/test/TaskLocalServiceTest.java

May service class:

https://github.com/naderjafari/liferay-todo-list/blob/Liferay-7.2.1-fix-test/liferay-todo-list-service/src/main/java/com/chberndt/liferay/todo/list/service/impl/TaskLocalServiceImpl.java
thumbnail
Nader Jafari, modified 5 Years ago. Junior Member Posts: 84 Join Date: 8/24/11 Recent Posts
I resolved this issue with updating my workspace :
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; classpath group: "com.liferay", name: "com.liferay.gradle.plugins.workspace", version: "2.2.11"

in setting.gradle.
Now everything is OK after executing buildService task.