Instance a service within a service implementation class

Hello,

I would like to know if its possible to instance a global service propety within a service impletation class? So far I’ve followed the same pattern being used to instance the DAO property, that means including the bean reference inside the bean definition of the targeted class.

<bean id="dermatology.DermaAnnotation"
      class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="transactionManager">
        <ref bean="transactionManager" />
    </property>
    <property name="target">
        <bean class="org.openmrs.module.dermatology.api.impl.DermaAnnotationServiceImpl">
            <property name="dao">
                <bean class="org.openmrs.module.dermatology.api.db.hibernate.HibernateDermaAnnotationDAO">
                    <property name="sessionFactory">
                        <ref bean="dbSessionFactory" />
                    </property>
                </bean>
            </property>
            <property name="msgLogService">
                <ref bean="dermatology.MessageLog"/>
            </property>
        </bean>
    </property>
    <property name="preInterceptors">
        <ref bean="serviceInterceptors" />
    </property>
    <property name="transactionAttributeSource">
        <ref bean="transactionAttributeSource" />
    </property>
</bean>
<bean parent="serviceContext">
    <property name="moduleService">
        <list>
            <value>org.openmrs.module.dermatology.api.DermaAnnotationService</value>
            <ref local="dermatology.DermaAnnotation"/>
        </list>
    </property>
</bean>

In this example I’m trying to instance a property type messageLogService inside DermaAnnotationImpl. I also defined the setters for the property msgLogService and I don’t have any warnings on my IDE. The problem I’m having at the moment, occurs during the server initialization and it freezes on this line…

Am I doing the correct procedures? Best Regards

Is the module’s source available on github for us to try reproduce?

i PMed you

Can you confirm that if you don’t add messageLogService property everything works fine?

Even when don’t add the property on moduleApplicationContext, it gets stuck on the part of the image that i posted yesterday

Best Regards

Then it’s another issue you are dealing with here, how long do you wait? It just takes a while but never hangs forever, you might have to wait long enough so you can look at the logs in case it eventually fails to catch the culprit.

Do you have a unit test where you call your service? Otherwise if you’re running the application it can be tough to zero down on the issue especially if you have several other modules installed.

I just got the basically for the server Reference application 2.8 and my own module, I had the server froze about 15min, and it didn’t seemed to bypass that message, do you know what causes the server to “freeze” like this? Even so i don’t got unit test, the last time I was stuck like this, the solution was changing the API classes for hibernate version 4 to version 3 to stop using bean annotations for the module classes

Typically class loading issues cause that delay, and I still urge you to let it stay running, it will eventually stop, I’ve seen longer delays than that before, you got to wait for the failure logs to trace the issue.

Alternatively you could do some logging from the classloader(s) and see what the offending class is.

To fix the freezing, remove this from your constructor of the DermaAnnotationServiceImpl class:

msgLogService = Context.getService(MessageLogService.class)
1 Like

Thank you two, i removed my suggestion, because i didn’t want to call the Context every time… oh well if its the solution who i am to change it :sweat_smile: