RE: How to inject spring bean in liferay service module.

Mohit Mehral, modified 6 Years ago. New Member Posts: 2 Join Date: 1/16/19 Recent Posts
Hi Everyone,

I am using Liferay dxp.

I need help in using the spring bean in liferay service module created using service builder.

I have created a spring mvc portlet using Liferay LDS and created one bean as Demo.java(having some getters and setters in it).
spring xml file is
"<?xml version="1.0"?>
 
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    default-destroy-method="destroy" default-init-method="afterPropertiesSet"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
    <bean id="com.lifery.practice.Demo" class="com.lifery.practice.Demo" />
</beans>"



In my service module(LocalServiceImpl file) i have referenced it as 

@BeanReference(type=Demo.class)
private Demo demo;


I have resolved the compile time dependency using below line in build.gradle
compileOnly project(":wars:Example")



When i try to start my service module through gogo shell i am getting below error

org.osgi.framework.BundleException: Could not resolve module: .service [960]
  Unresolved requirement: Import-Package: com.lifery.practice


I am stuck here.

Do we have register the bean in application context?


How to acheive this scenario?? Please help!!!


Regards,
​​​​​​​Mohit Mehral.
thumbnail
Amos Fong, modified 6 Years ago. Liferay Legend Posts: 2047 Join Date: 10/7/08 Recent Posts
The spring MVC Portlet is a WAR right? Try exporting that package in liferay-plugin-package.properties.
​​​​​​​
https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/exporting-packages