org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'patientdetailsController':

Hello, I created my first module named “patientdetails” . I then configured spring mvc . And now configuring hibernate throws an server error 500… I created service, serviceImpl, dao and daoImpl classes and added bean according to Module Application Context File - Documentation - OpenMRS Wiki in the /omod/src/main/resources/webModuleApplicationContext.xml but its throws eror when deploying the module. At first it shows EntityManger closed.Error is

Need of help… :thinking:

Do you mind pushing your module to GitHub such that we take a closer look?

Yes :point_down:

1 Like

Thanks @dkayiwa Have solved some errors by adding bean in the api webModuleApplicationContext.xml but still facing another server error

And i was wondering if we use @service in the serviceImpl class so far changes at GitHub - Muta-Jonathan/Patientdetails: Changes in firstmodule_openmrs

hello @jonathan the cause is `

org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.openmrs.module.patientdetails.service.PatientdetailsService' available: expected single matching bean but found 2: patientdetailsServiceImpl,patientdetails.PatientdetailsService which is about the bean configurations in your moduleApplicationContext

You can follow this sample

> `<bean parent=` `"serviceContext"` `>`
> 
> `    ` `<property name=` `"moduleService"` `>`
> 
> `        ` `<list>`
> 
> `            ` `<value>org.openmrs.module.formentry.FormEntryService</value> <!-- Your service's ` `interface` `class` `-->`
> 
> `            ` `<bean ` `class` `=` `"org.springframework.transaction.interceptor.TransactionProxyFactoryBean"` `>`
> 
> `                ` `<property name=` `"transactionManager"` `><ref bean=` `"transactionManager"` `/></property>`
> 
> `                ` `<property name=` `"target"` `>`
> 
> `                    ` `<bean ` `class` `=` `"org.openmrs.module.formentry.impl.FormEntryServiceImpl"` `> <!-- Your service's concrete ` `class` `-->`
> 
> `                        ` `<property name=` `"formEntryDAO"` `> <!-- Name of the DAO property on your ServiceImpl -->`
> 
> `                            ` `<bean ` `class` `=` `"org.openmrs.module.formentry.db.hibernate.HibernateFormEntryDAO"` `> <!-- Your DAO's concrete ` `class` `-->`
> 
> `                                ` `<property name=` `"sessionFactory"` `><ref bean=` `"sessionFactory"` `/></property>`
> 
> `                            ` `</bean>`
> 
> `                        ` `</property>`
> 
> `                    ` `</bean>`
> 
> `                ` `</property>`
> 
> `                ` `<property name=` `"preInterceptors"` `>`
> 
> `                    ` `<ref bean=` `"serviceInterceptors"` `/>`
> 
> `                ` `</property>`
> 
> `                ` `<property name=` `"transactionAttributeSource"` `>`
> 
> `                    ` `<bean ` `class` `=` `"org.springframework.transaction.annotation.AnnotationTransactionAttributeSource"` `/>`
> 
> `                ` `</property>`
> 
> `            ` `</bean>`
> 
> `        ` `</list>`
> 
> `    ` `</property>`
> 
> `</bean>`
> 
> `

Also remove

 <!-- Adds PatientdetailsService to OpenMRS context so it can be accessed
    calling Context.getService(PatientdetailsService.class) -->
    <bean parent="serviceContext">
        <property name="moduleService">
            <list>
                <value>org.openmrs.module.patientdetails.service.PatientdetailsService</value>
                <ref bean="patientdetails.PatientdetailsService" />
            </list>
        </property>
    </bean>
1 Like

Thanks @gcliff let me try the changes

Thanks @gcliff , @dkayiwa , @sharif and @mozzy …Have been able to save data in database Error solved All in all Module Application Context File already when created it has already set up beans :grinning:

1 Like

By default, the moduleApplicationContext.xml will do for you the required SpringConfiguration for the default service class and the hibernate layer classes.
Any Spring error that shows up is most probably caused by some thing else , So you ddnt have to tamper with the moduleApplicationContext.xml configurations

1 Like