Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to import/initialize beans from other modules?

 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic