• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

How to import/initialize beans from other modules?

 
Ranch Hand
Posts: 806
MySQL Database Spring Java
  • 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.
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • 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
MySQL Database Spring Java
  • 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.
 
Yup, yup, yup. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic