- 浏览: 248717 次
- 性别:
- 来自: 深圳
-
文章分类
最新评论
-
sweed0:
为何每一段代码都重复一次呢?
spring注解实例二 -
Gary_Huangpf:
- - 插件报错啊
Ext前台分页 -
ddvk2007:
版主 我想請問你所說的mapreduce是hadoop的還是g ...
MapReduce中的Shuffle和Sort分析 -
人可木:
好问章,楼主写的相当详细。。。多谢。。。
findbugs插件的安装与应用 -
hautbbs:
按照博主的方法启动调试出现jvm terminated.Ex ...
10分钟学会使用MyEclipse断点调试js
1、web.xml配置文件:
<?xml version="1.0" encoding="gb2312"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<!--
- Location of the Log4J config file, for initialization and refresh checks.
- Applied by Log4jConfigListener.
-->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.xml</param-value>
</context-param>
<!-- 为了能够加载日志文件,故需要配置一个日志监听器 -->
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<!-- 设置Ioc配置文件的名称为
/WEB-INF/applicationContext.xml,
/WEB-INF/classes/jdbc.xml,
/WEB-INF/spring-config.xml,
/WEB-INF/config/spring/*.xml
如果不配置,则它会读取默认的文件名/WEB-INF/action-servlet.xml-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml,
/WEB-INF/classes/jdbc.xml,
/WEB-INF/spring-config.xml,
/WEB-INF/config/spring/*.xml
</param-value>
</context-param>
<!-- 为了能够加载Spring的Bean配置,故配置一个监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- filters -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- spring Dispatcher -->
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!-- 异常处理 -->
<error-page>
<error-code>404</error-code>
<location>/commons/404.jsp</location>
</error-page>
<!--
<error-page>
<error-code>500</error-code>
<location>/commons/error.jsp</location>
</error-page>-->
<!-- 没有数据的异常处理
<error-page>
<exception-type>org.springframework.dao.EmptyResultDataAccessException</exception-type>
<location>/commons/nodata.jsp</location>
</error-page>
-->
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
2、视图解析器的配置
<!-- Defination of view Resolver -->
<!-- 视图解析器的配置InternalResourceViewResolver
它支持InternalResourceView(对servlet和jsp的包装),以及其子类JstlView和TilesView
通过setViewClass方法,可以指定用于该解析器生成视图使用的视图类。如下为:JstlView视图类。
-->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass">
<value>org.springframework.web.servlet.view.JstlView</value>
</property>
</bean>
3、处理器的配置<!-- Controller配置 -->
<!-- 登录演示
为了选择不同的方法入口,我们需要定义方法解析器。ParameterMethodNameResolver为最常用的。
ParameterMethodNameResolver 为默认的解析器实现类,并指定提取方法名的参数为action,
默认的方法名为showLoginForm。
-->
<bean id="loginAction" class="com.ztes.sl.rmtes.action.demo.LoginAction">
<property name="methodNameResolver">
<bean class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver">
<property name="paramName"><value>action</value></property>
<property name="defaultMethodName"><value>showLoginForm</value></property>
</bean>
</property>
<property name="formView" value="/pages/demo/login.jsp"/>
<property name="successView" value="/pages/demo/loginSuccess.jsp"/>
</bean>
4、处理器映射的配置
<!-- 1. SimpleUrlHandlerMapping是最常用的HandlerMapping处理器映射,
它在应用上下文中可以进行配置,并且有Ant风格的路径匹配功能。
2.其中定义了一个拦截器(spring的处理器映射支持拦截器),它必须实现HandlerInterceptor
接口,这个接口定义了3个方法,一个在处理器执行前被调用,一个在处理器执行后被调用,另一个在
整个请求处理完成后被调用。
3.下面的例子提供了一个拦截器RequestHandlerInterceptor,它拦截mappings中的所有请求。
-->
<bean id="urlMappingAlarmRight" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="interceptors">
<list>
<ref bean="RequestHandlerInterceptor" />
</list>
</property>
<property name="mappings">
<props>
<!-- 列表 -->
<prop key="/alarm/forecast.do">forecastAction</prop>
</props>
</property>
</bean>
发表评论
-
spring AOP
2012-06-13 11:14 928先简单的说说spring aop使用的好处:利用AOP横向添加 ... -
spring IOC的使用
2012-06-13 10:58 969Ioc和他的作用,简单的来讲,就是由容器控制程序之间的关 ... -
spring IOC介绍
2012-06-13 10:55 1366首先想说说IoC(Inversion of ... -
spring概述
2012-06-13 10:52 817随着越来越多的项目 ... -
spring学习总结
2010-02-04 08:49 978先说说简单地使用Struts2做Web时的经历: 1.经常需要 ... -
spring注解实例二
2010-01-26 11:22 2384昨天对Spring注解有了一个整体认识,至少完成了一个简单的w ... -
spring注解实例一
2010-01-26 11:15 2951先来构建一个极为简单的web应用,从controller到da ... -
spring注解配置文件解析
2010-01-26 11:01 35841、applicationContext.xml ... -
使用 Spring 2.5 基于注解驱动的 Spring MVC(二)
2010-01-22 11:13 3439我们在 ② 处添加了一个 ModelMap 属性,其属性名为 ... -
使用 Spring 2.5 基于注解驱动的 Spring MVC(一)
2010-01-22 11:05 1376基于注解的配置有越来越流行的趋势,Spring 2.5 顺应这 ... -
spring注解详解
2010-01-22 09:57 13581.准备工作(1)导入common-annotations.j ... -
spring注解
2010-01-13 09:56 1032Spring JSR-250注解 注释配 ... -
Spring MVC 配置【转】
2010-01-03 14:51 1073一,配置分发器 Dispatche ... -
spring mvc 学习笔记
2010-01-03 14:41 1168一、与struts的不同 1.Spr ... -
Spring Mvc快速入门
2010-01-03 14:20 1756Spring MVC是结构最清晰的MVC ... -
Spring 可代码简化操作类
2009-12-28 09:31 1070SimpleJdbcTemplate类是Jd ... -
Spring 命名参数操作类NamedParameterJdbcTemplate
2009-12-28 09:28 1813在传统的SQL语句中,参数都是用'?'占 ... -
Spring JdbcTemplate操作类
2009-12-24 10:42 27991.JdbcTemplate ...
相关推荐
接下来,一旦检测到Spring配置文件发生变化,我们需要重新加载配置文件。这可以通过Spring的`ApplicationContext`的`refresh()`方法来实现。`refresh()`会重新初始化Bean工厂,读取新的配置信息,并更新所有Bean的...
DispatcherServlet 是继承自 HttpServlet 的,既然 SpringMVC 是基于DispatcherServlet 的,那么我们先来配置一下 DispatcherServlet,好让它能够管理我们希望它管理的内容。 在 web.xml 文件中声明 ...
本篇文章将深入探讨如何在Spring中配置Freemarker视图解析器,以及如何配置多个视图解析器以实现更灵活的应用场景。 首先,让我们了解如何配置单个Freemarker视图解析器。在Spring的配置文件(如`...
在本文中,我们将深入探讨Spring Security的配置及其在实际应用中的使用。 首先,Spring Security的核心概念包括用户、角色、权限和访问控制。它提供了一种机制来验证用户身份(身份验证),并决定用户是否可以访问...
5. `spring-servlet.xml`: 这是Spring MVC的核心配置文件,配置了DispatcherServlet的处理器映射器、视图解析器、拦截器等,定义了Spring MVC的运行环境。 6. `web.xml`: 这是JavaWeb应用的部署描述符,定义了...
### Spring源码分析:配置文件读取流程 - ImportNew #### 概述 Spring框架作为Java企业级开发中广泛使用的轻量级框架之一,其核心功能之一便是通过依赖注入(DI)来管理对象间的依赖关系。Spring框架的核心是其IOC...
阐述spring的数据源配置
#### 三、配置解析 从上述配置可以看出,Spring AOP主要是通过`ProxyFactoryBean`来创建代理对象,通过配置不同的拦截器来实现对目标对象方法的增强。这种配置方式非常灵活,可以根据实际需求动态地添加或修改拦截...
本文将深入探讨Spring如何通过读取配置文件实现依赖注入,并讲解相关源码,帮助理解其工作原理。 在Spring中,配置文件通常为XML格式,如`applicationContext.xml`,它定义了bean的实例化、属性设置、装配关系等。...
本文将深入探讨Spring与Spring MVC的整合配置,并结合标签"源码"和"工具"来解析相关的技术细节。 首先,Spring框架的核心特性包括依赖注入(Dependency Injection, DI)和面向切面编程(Aspect-Oriented ...
- Spring MVC使用注解进行配置,减少了XML配置的繁琐,使得配置更加简洁易懂。 - Spring MVC支持RESTful风格的URL,适合构建现代Web应用。 - 它可以方便地集成Spring的其他模块,如Spring Security进行权限管理,...
源码分析是理解Spring配置文件的另一个重要途径。Spring框架是开源的,我们可以通过阅读源码来了解其内部工作原理。例如,`ApplicationContext`接口和其实现类如`ClassPathXmlApplicationContext`,它们负责加载和...
二、Spring配置文件 1. **beans.xml**:这是Spring应用中最常见的配置文件,用于定义bean及其依赖关系。在这里,我们可以声明bean的类、属性、初始化方法、依赖注入等。 2. **applicationContext.xml**:此文件通常...
在Spring 2.5中,应用的配置信息通常存储在`applicationContext.xml`或相关的XML配置文件中。配置VM选项通常是通过在启动命令行时添加`-D`参数来实现的,例如`java -Dproperty.name=value -jar yourApp.jar`。这里的...
在这个"Spring Boot druid 以及相关sql、Spring监控配置demo"中,我们将探讨如何在Spring Boot项目中集成Druid数据源,以及如何配置SQL监控和Spring的监控功能。 首先,让我们了解Druid数据源的核心特性: 1. **高...
6. **配置Spring MVC**:如果项目中还包含了Spring MVC,那么还需要配置DispatcherServlet,设置视图解析器、模型数据绑定、拦截器等。 7. **测试**:完成上述配置后,通过单元测试或者运行应用进行测试,确保...
为了使Spring Boot能够找到JAR内的配置文件,可以在`src/main/resources`目录下创建`META-INF/spring.factories`文件,并添加以下内容: ``` org.springframework.boot.autoconfigure.EnableAutoConfiguration=...
下面将详细阐述Spring MVC配置的六个关键步骤,以及与之相关的知识点。 **步骤1:引入Spring MVC依赖** 在开始Spring MVC项目之前,首先需要在项目中添加Spring MVC的依赖库。这通常通过在Maven或Gradle的构建文件...
本篇文章将深入探讨Spring的核心工厂配置源码,以及在Eclipse 3.2和Tomcat 5.0环境下如何进行开发。 首先,我们需要理解Spring中的Bean工厂,它是IoC容器的基础。Bean工厂负责管理对象的生命周期和依赖关系。在...
在本压缩包中,你将找到Spring4版本的相关jar包,这些是运行Spring应用的基础。Spring4相较于之前的版本,引入了更多优化和新特性,如更好的Java 8支持、对WebSocket的支持等。 首先,我们来了解一下Spring框架的...