Forums de discussion
DXP ServiceBuilder,unable to inject services
Zak Thompson, modifié il y a 6 années.
DXP ServiceBuilder,unable to inject services
Junior Member Publications: 70 Date d'inscription: 13/06/16 Publications récentes
I am working on a service builder module and I'm attempting to inject the following services into my local service impl:
My first attempt at injecting them was to use setter methods with OSGI Reference annotations, but the services were null when my custom service methods were called:
I then tried to add ServiceReference annotations to the services, but this results in exceptions being thrown when the module is deployed:
Exception:
I also have tried adding the following to my service xml to inject the service, but it gives me an error in the build service task:
Error:
What is the proper way to inject these services into my servicebuilder component?
private AssetCategoryPropertyLocalService assetCategoryPropertyLocalService;
private AssetVocabularyLocalService assetVocabularyLocalService;
My first attempt at injecting them was to use setter methods with OSGI Reference annotations, but the services were null when my custom service methods were called:
@Reference(unbind = "-")
protected void setAssetCategoryPropertyLocalService(final AssetCategoryPropertyLocalService assetCategoryPropertyLocalService){
this.assetCategoryPropertyLocalService = assetCategoryPropertyLocalService;
}
@Reference(unbind = "-")
protected void setAssetVocabularyLocalService(final AssetVocabularyLocalService assetVocabularyLocalService) {
this.assetVocabularyLocalService = assetVocabularyLocalService;
}
I then tried to add ServiceReference annotations to the services, but this results in exceptions being thrown when the module is deployed:
@ServiceReference
private AssetCategoryPropertyLocalService assetCategoryPropertyLocalService;
@ServiceReference
private AssetVocabularyLocalService assetVocabularyLocalService;
Exception:
[com_liferay_portal_spring_extender:103] Invocation of 'start' failed.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.company.site.integrity.service.SiteIntegrityLocalService' defined in URL [bundleentry://665.fwk725273950/META-INF/spring/module-spring.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.company.site.integrity.service.impl.SiteIntegrityLocalServiceImpl': Unable to inject bean reference fields; nested exception is java.lang.IllegalArgumentException: Can not set com.liferay.asset.kernel.service.AssetCategoryPropertyLocalService field com.company.site.integrity.service.impl.SiteIntegrityLocalServiceImpl.assetCategoryPropertyLocalService to com.liferay.blogs.web.internal.auth.publicpath.AuthPublicPath
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:762)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at com.liferay.portal.spring.extender.internal.context.ModuleApplicationContextRegistrator._createApplicationContext(ModuleApplicationContextRegistrator.java:144)
at com.liferay.portal.spring.extender.internal.context.ModuleApplicationContextRegistrator.start(ModuleApplicationContextRegistrator.java:61)
at sun.reflect.GeneratedMethodAccessor380.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.felix.dm.InvocationUtil.invokeMethod(InvocationUtil.java:111)
at org.apache.felix.dm.InvocationUtil.invokeCallbackMethod(InvocationUtil.java:66)
at org.apache.felix.dm.impl.ComponentImpl.invokeCallbackMethod(ComponentImpl.java:769)
at org.apache.felix.dm.impl.ComponentImpl.invoke(ComponentImpl.java:760)
at org.apache.felix.dm.impl.ComponentImpl.bindService(ComponentImpl.java:705)
at org.apache.felix.dm.impl.ComponentImpl.access$400(ComponentImpl.java:54)
at org.apache.felix.dm.impl.ComponentImpl$7.run(ComponentImpl.java:202)
at org.apache.felix.dm.impl.SerialExecutor.runTask(SerialExecutor.java:137)
at org.apache.felix.dm.impl.SerialExecutor.runTasks(SerialExecutor.java:119)
at org.apache.felix.dm.impl.SerialExecutor.execute(SerialExecutor.java:85)
at org.apache.felix.dm.impl.ComponentImpl.calculateStateChanges(ComponentImpl.java:252)
at org.apache.felix.dm.impl.ComponentImpl.start(ComponentImpl.java:440)
at org.apache.felix.dm.DependencyManager.add(DependencyManager.java:167)
at com.liferay.portal.spring.extender.internal.context.ModuleApplicationContextExtender$ModuleApplicationContextExtension.start(ModuleApplicationContextExtender.java:223)
at org.apache.felix.utils.extender.AbstractExtender.createExtension(AbstractExtender.java:259)
at org.apache.felix.utils.extender.AbstractExtender.modifiedBundle(AbstractExtender.java:232)
at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:482)
at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:1)
at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:232)
at org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:444)
at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:905)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEventPrivileged(EquinoxEventPublisher.java:165)
at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:75)
at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:67)
at org.eclipse.osgi.internal.framework.EquinoxContainerAdaptor.publishModuleEvent(EquinoxContainerAdaptor.java:102)
at org.eclipse.osgi.container.Module.publishEvent(Module.java:461)
at org.eclipse.osgi.container.Module.start(Module.java:452)
at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:454)
at org.eclipse.osgi.container.ModuleContainer.applyDelta(ModuleContainer.java:717)
at org.eclipse.osgi.container.ModuleContainer.resolveAndApply(ModuleContainer.java:491)
at org.eclipse.osgi.container.ModuleContainer.resolve(ModuleContainer.java:437)
at org.eclipse.osgi.container.ModuleContainer.refresh(ModuleContainer.java:955)
at org.eclipse.osgi.container.ModuleContainer$ContainerWiring.dispatchEvent(ModuleContainer.java:1336)
at org.eclipse.osgi.container.ModuleContainer$ContainerWiring.dispatchEvent(ModuleContainer.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.company.site.integrity.service.impl.SiteIntegrityLocalServiceImpl': Unable to inject bean reference fields; nested exception is java.lang.IllegalArgumentException: Can not set com.liferay.asset.kernel.service.AssetCategoryPropertyLocalService field com.company.site.integrity.service.impl.SiteIntegrityLocalServiceImpl.assetCategoryPropertyLocalService to com.liferay.blogs.web.internal.auth.publicpath.AuthPublicPath
at com.liferay.portal.spring.extender.internal.bean.ServiceReferenceAnnotationBeanPostProcessor.autoInject(ServiceReferenceAnnotationBeanPostProcessor.java:101)
at com.liferay.portal.spring.extender.internal.bean.ServiceReferenceAnnotationBeanPostProcessor.postProcessBeforeInitialization(ServiceReferenceAnnotationBeanPostProcessor.java:67)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:408)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1564)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
... 51 more
Caused by: java.lang.IllegalArgumentException: Can not set com.liferay.asset.kernel.service.AssetCategoryPropertyLocalService field com.company.site.integrity.service.impl.SiteIntegrityLocalServiceImpl.assetCategoryPropertyLocalService to com.liferay.blogs.web.internal.auth.publicpath.AuthPublicPath
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81)
at java.lang.reflect.Field.set(Field.java:764)
at com.liferay.portal.spring.extender.internal.bean.ServiceReferenceAnnotationBeanPostProcessor.autoInject(ServiceReferenceAnnotationBeanPostProcessor.java:95)
... 55 more
I also have tried adding the following to my service xml to inject the service, but it gives me an error in the build service task:
<reference entity="AssetVocabulary" package-path="com.liferay.portal" />
Error:
Unable to find AssetVocabulary in Account,Address,BrowserTracker,ClassName,ClusterGroup,Company,Contact,Country,EmailAddress,Group,Image,Layout,LayoutBranch,LayoutFriendlyURL,LayoutPrototype,LayoutRevision,LayoutSet,LayoutSetBranch,LayoutSetPrototype,LayoutTemplate,ListType,MembershipRequest,Organization,OrgGroupRole,OrgLabor,PasswordPolicy,PasswordPolicyRel,PasswordTracker,Permission,Phone,PluginSetting,Portal,PortalPreferences,Portlet,PortletItem,PortletPreferences,RecentLayoutBranch,RecentLayoutRevision,RecentLayoutSetBranch,Region,Release,Repository,RepositoryEntry,Resource,ResourceAction,ResourceBlock,ResourceBlockPermission,ResourcePermission,ResourceTypePermission,Role,ServiceComponent,Subscription,SystemEvent,Team,Theme,Ticket,User,UserGroup,UserGroupGroupRole,UserGroupRole,UserIdMapper,UserNotificationDelivery,UserNotificationEvent,UserTracker,UserTrackerPath,VirtualHost,WebDAVProps,Website,WorkflowDefinitionLink,WorkflowInstanceLink
What is the proper way to inject these services into my servicebuilder component?
David H Nebinger, modifié il y a 6 années.
RE: DXP ServiceBuilder,unable to inject services
Liferay Legend Publications: 14917 Date d'inscription: 02/09/06 Publications récentes
Change to:
<reference entity="AssetVocabulary" package-path="com.liferay.portlet.asset" />
Come meet me at the 2017 LSNA!
<reference entity="AssetVocabulary" package-path="com.liferay.portlet.asset" />
Come meet me at the 2017 LSNA!
Zak Thompson, modifié il y a 6 années.
RE: DXP ServiceBuilder,unable to inject services
Junior Member Publications: 70 Date d'inscription: 13/06/16 Publications récentes
That worked, thanks David!
Amos Fong, modifié il y a 4 années.
RE: DXP ServiceBuilder,unable to inject services
Liferay Legend Publications: 2047 Date d'inscription: 07/10/08 Publications récentes
I just ran into this error as well (Liferay DXP 7.0) and adding "type" to the ServiceReference fixed it for me:
@ServiceReference(type = AccountWebService.class)
private AccountWebService _accountWebService;