wood burning stoves 2.0*
The moose likes Spring and the fly likes How to import/initialize beans from other modules? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "How to import/initialize beans from other modules?" Watch "How to import/initialize beans from other modules?" New topic
Author

How to import/initialize beans from other modules?

chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

Hi all, I am working on a web application which is divided into two modules.

1. api
2. ui

api contains repository/DAO classes and service classes. I am using mybatis as ORM. I am having an app-context for api in which I am creating org.mybatis.spring.SqlSessionFactoryBean. This bean is passed a datasource. My DAO extends SqlSessionDaoSupport. When I am running tests on my DAO classes the tests are running fine.

However when I add the api jar to my ui and try to get the instance of a service class in any controller I am getting an error saying Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required.

I understood that the beans in api are not getting initialized.

It means the app-context.xml in api is not being read by spring container.

How can I in initialize beans in app-context.xml of api module? or should I create all those beans in ui app-context.xml again?

Thank you all in advance. Good day.


Love all, trust a few, do wrong to none.
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1672
    
    7

chaitanya karthikk wrote:
It means the app-context.xml in api is not being read by spring container.


Can you post your web.xml and the relevant parts of your configuration files.


[How To Ask Questions][Read before you PM me]
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

Hi Bill, I figured it out. I have to import the api's application context into ui's application context. This did the fix

<import resource="classpath:core-app-context.xml" />

Thanks for replying.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to import/initialize beans from other modules?