Security Spring 3.0/Hibernate配置文件的参考问题

Security Spring 3.0/Hibernate配置文件的参考问题,security,hibernate,spring,Security,Hibernate,Spring,全部, 我最初是这样设置的,一切都按预期进行 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

全部,

我最初是这样设置的,一切都按预期进行

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 ...
spring-servlet.xml具有

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

如何让我的应用程序与Spring Security一起工作,并将所有datasource/hibernate内容放在一个地方?

在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>

上下文配置位置
/WEB-INF/spring-security.xml
类路径:datasource-cfg.xml
org.springframework.web.context.ContextLoaderListener

但是,我不会混搭配置文件的位置;在我看来,最好将它们放在一个地方,可能在类路径上。

您如何配置spring以使用附加的配置文件?啊,您可能发现了一些问题。Spring Security让您将其添加到web.xml中的类路径中。contextConfigLocation/WEB-INF/spring-security.xml类路径:datasource-cfg.xml我不知道如何添加类路径,以便应用程序的其余部分可以看到datasource-cfg.xml是否会添加到spring-servlet.xml、WEB.xml等中?@user973479:哪些类正在使用
@Transactional
?它们是在哪个文件中声明的?整个应用程序中都有大量事务性注释,用于处理CRUD内容,这些注释过去是有效的。我的web.xml中已经有了这些注释,所以肯定还有其他一些事情我不知道seeing@user973479您确定正在部署datasource配置文件吗?是的,因为身份验证工作正常,这取决于它,我明白了。我必须手动覆盖applicationContext的默认值,并将新文件添加到DispatchServlet的类路径中。这与上面显示的类似,只是它引用了不同的xml文件。(因此,这需要和上面显示的一样完成)contextConfigLocation/WEB-INF/classes/applicationContext.xml类路径:datasource.xml@user973479啊,是的,对不起;我不是从现有的项目中复制。我会用你的补充信息更新答案。很高兴你解决了这个问题——我在这上面花了不少时间:/applicationContext放在context参数中不起作用吗?
<context:component-scan base-package="foo" />
<bean ...
<tx:annotation-driven/>
<bean id="dataSource" ...
<bean id="sessionFactory" ...
<bean id="transactionManager" ...
<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)
<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>