tags:

views:

1495

answers:

2

we have 3 applications using 3 different spring configuration files. But we have one database and one datasource,so one sessionFactory. how can we import the sessionFactory bean into the 3 different spring config files.

+2  A: 

If you are using XML configuration:

Put your database settings in a Spring configuration called "database-config.xml" and import it in the other configuration files.

<import resource="database-config.xml"/>

As to how you share it among three applications is more of a Configuration Management issue. You could use ant / maven to check it out of a repository and move it into the correct location.

Paul Croarkin
+4  A: 

Configure your SessionFactory in a single XML file and import this configuration into whichever applications' Spring contexts need it.

If you use classpath-based importing like this:

<beans>
    <import resource="classpath:path/to/session-factory-beans.xml"/>
    <... other bean definitions.../>
</beans>

Then your distribution mechanism is pretty flexible, since the classloader will resolve the resource for you. You could

  • copy session-factory-beans.xml into each project that requires it, or
  • add it to a jarfile and share that amongst the applications, or
  • add it to shared/classes if the applications are all running inside the same application server.
Dan Vinton