I have a hibernate.cfg.xml file, but I’d like to reference it as a dataSource bean. Is there any way to do this? All I have is :
<beans:bean id="foo" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<beans:property name="configLocation" value="classpath:hibernate.cfg.xml"/>
but its not a dataSource. Any help would be greatly appreciated.
To add a bit of context, I’d like to integrate Spring Security in my app and one of the ways to provide a database as a source for the authentication manager is as follows (taken from here):
<authentication-manager>
<authentication-provider>
<jdbc-user-service data-source-ref="securityDataSource"/>
</authentication-provider>
</authentication-manager>
Where “securityDataSource” is the name of a DataSource bean in the application context, pointing at a database.
You have two options:
If you’re not using the
hibernate.cfg.xmlanywhere else, you can eliminate it altogether and just use Spring’s configuration (see below)If you need
hibernate.cfg.xmlfor some reason (you’re using it elsewhere), then keep that file and add Spring configurationExample configuration (notice database access is in a separate
dataSourcebean)You can see more information about the configuration options in http://static.springsource.org/spring/docs/current/spring-framework-reference/html/orm.html