0

I have 2 spring configurations :

spring-servlet.xml
spring-security.xml

needed to add this line to security:

<beans:import resource="spring-servlet.xml"/>

Now hibernate is ran twice, this is log screenshot :

enter image description here

my web.xml:

<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>


<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
      </listener-class>
</listener>
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/spring-security.xml
    </param-value>
</context-param>
4

1 回答 1

0

删除<beans:import resource="spring-servlet.xml"/>,

并设置

<param-value>
    /WEB-INF/spring-security.xml;/WEB-INF/spring-servlet.xml 
</param-value>

也许你两次定义 sessionFactory bean。删除其中之一。

编辑:

好的,两个上下文是正常的。一 - 应用程序上下文,由 加载ContextLoaderListener,应该包含 sessionFactory、dao、services 等的定义。通常它的名字是applicationContext.xml

DispatcherServlet 应该只包含 MVC 的 bean。您可以在参数中定义 conext 名称:

<init-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>WEB-INF/spring-servlet.xml</param-value>
</init-param>
于 2012-12-11T10:28:04.033 回答