All,
I originally had my setup like this and everything worked as expected.
WEB-INF
|--spring-servlet.xml
|--classes
|--hibernate-cfg.xml
spring-servlet.xml had
<context:component-scan base-package="foo" />
<tx:annotation-driven/>
<bean id="dataSource" ...
<bean id="sessionFactory" ...
<bean id="transactionManager" ...
<bean ...
hibernate-cfg.xml had
<hibernate-configuration>
<session-factory>
<mapping ...
I wanted to add Spring Security to the mix to handle user authentication. To get this to work, I had to refactor some stuff. My new setup looks like this:
WEB-INF
|--spring-servlet.xml
|--classes
|--datasource-cfg.xml
|--hibernate-cfg.xml
spring-servlet.xml has
<context:component-scan base-package="foo" />
<bean ...
datasource-cfg.xml has
<tx:annotation-driven/>
<bean id="dataSource" ...
<bean id="sessionFactory" ...
<bean id="transactionManager" ...
hibernate-cfg.xml has
<hibernate-configuration>
<session-factory>
<mapping ...
The authentication piece now works, but the previously working pieces no longer work.
I now get the following message:
No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
at org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63)
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:687)
How can I get my app to work with Spring Security and have all the datasource/hibernate stuff in one place?
This in the web.xml should be enough.
I wouldn’t mix-and-match where the config files go, however; IMO it’s best to keep them all in one place, probably on the classpath.