小编Fah*_*ail的帖子

弹簧3.2.3的最佳配置

我正在尝试了解弹簧配置.我读了两篇文章:

  1. http://www.onjava.com/pub/a/onjava/2006/03/22/advanced-spring-configuration.html?page=1
  2. http://syntx.io/difference-between-loading-context-via-dispatcherservlet-and-contextloaderlistener/

这些建议有2个配置文件:"应用程序上下文"和"Web应用程序上下文".

如果您曾尝试使用Spring MVC框架开发Web应用程序,您知道应该使用两个配置文件:

/WEB-INF/applicationContext.xml允许您配置bean,或指示应用程序的上下文.您可以在此处定义业务逻辑bean,资源以及与Web层不直接相关的所有其他Bean.

/WEB-INF/[servlet-name]-servlet.xml用于配置Web层并查看MVC框架中需要的解析器,控制器,验证器和所有其他bean.[servlet-name]是指在web.xml部署描述符中定义的Spring的调度程序servlet的名称.

根据这个,我写我的web.xml如下:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">


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

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml,
            /WEB-INF/spring-security.xml</param-value>
    </context-param>


    <!-- Spring MVC -->
    <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>


    <!-- Spring Security -->
    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>
            org.springframework.web.filter.DelegatingFilterProxy
        </filter-class>
    </filter>

    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <!-- Fin Spring Security -->

</web-app>
Run Code Online (Sandbox Code Playgroud)

这是我的applicationContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:jee="http://www.springframework.org/schema/jee"
  xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:beans="http://www.springframework.org/schema/beans"
  xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
  xsi:schemaLocation="http://www.springframework.org/schema/mvc …
Run Code Online (Sandbox Code Playgroud)

spring hibernate spring-mvc

3
推荐指数
1
解决办法
6269
查看次数

标签 统计

hibernate ×1

spring ×1

spring-mvc ×1