2011-11-07 11 views
0

所有,與Spring 3.0參考號/ Hibernate的配置文件

我原本我的設置是這樣,一切工作正常。

WEB-INF 
|--spring-servlet.xml 
|--classes 
    |--hibernate-cfg.xml 

爲spring-servlet.xml有

<context:component-scan base-package="foo" /> 
<tx:annotation-driven/> 
<bean id="dataSource" ... 
<bean id="sessionFactory" ... 
<bean id="transactionManager" ... 
<bean ... 

休眠-cfg.xml中有

<hibernate-configuration> 
    <session-factory> 
    <mapping ... 

我想Spring Security的加進來來處理用戶身份驗證。爲了使這個工作,我不得不重構一些東西。我的新的設置是這樣的:

WEB-INF 
|--spring-servlet.xml 
|--classes 
    |--datasource-cfg.xml 
    |--hibernate-cfg.xml 

爲spring-servlet.xml有

<context:component-scan base-package="foo" /> 
<bean ... 

數據源-cfg.xml中有

<tx:annotation-driven/> 
<bean id="dataSource" ... 
<bean id="sessionFactory" ... 
<bean id="transactionManager" ... 

休眠-cfg.xml中有

<hibernate-configuration> 
    <session-factory> 
    <mapping ... 

驗證件現在可以工作,但以前的工件不再工作。

我現在得到以下信息:

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) 

我怎樣才能得到我的應用程序與春季安全工作,並擁有所有的數據源/在一個地方冬眠的東西?

+0

你如何配置spring使用額外的配置文件? –

+0

啊,你可能會想到什麼。 Spring Security使您可以將它添加到web.xml中的類路徑中。 <的context-param> ​​contextConfigLocation的 /WEB-INF/spring-security.xml 類路徑:數據源-cfg.xml中 user973479

+0

我不知道如何添加類路徑,以便應用程序的其餘部分可以看到datasource-cfg.xml是否將添加到spring-servlet.xml,web.xml等? – user973479

回答

1

這在web.xml中應該就夠了。

<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value> 
    /WEB-INF/spring-security.xml 
    classpath:datasource-cfg.xml 
    </param-value> 
</context-param> 

<listener> 
    <listener-class> 
    org.springframework.web.context.ContextLoaderListener 
    </listener-class> 
</listener> 

我不會在配置文件去的地方混合搭配,但是;海事組織最好將它們全部放在一個地方,可能放在班級路線上。

+0

我已經在我的web.xml中有這些了,所以肯定還有別的事情發生我沒有看到 – user973479

+0

@ user973479你確定數據源配置文件正在被部署嗎? –

+0

是的,因爲驗證件工作,它依靠它 – user973479