Divs
Divs

Reputation: 1618

Can a non spring web application use a jar which is built using spring + hibernate

We are building a java application using spring hibernate maven. The jar will be used in a non spring web application that uses ejb and plain jdbc. Ejb will access the jar interface methods which in turn makes hibernate calls. What changes are needed in the web application to load the spring context during start up? Is it feasible?

Upvotes: 2

Views: 304

Answers (1)

Andrés Oviedo
Andrés Oviedo

Reputation: 1428

If you want to keep your jar decoupled from web application you should do this:

  • Copy your jar and all dependant jars to webapp WEB-INF\lib directory (or pom if maven)
  • Your Spring Context should be loaded in a static variable, in a safe thread manner; or if you want to integrate it to the webapp lifecycle you can do it in several ways: web.xml, web-fragment or using a servlet initializer. There are lot of documentation in Internet
  • If you continue to use hibernate or change to JDBC, the DataSource should be provided generally by the web container, so you must use InitialContext.lookup("") to get the actual DataSource.

Upvotes: 1

Related Questions