spring 框架的配置文件
2016-01-14 09:28
441 查看
首先要导入需要的jar包配置web.xml:
<!-- Spring MVC配置 --> <!-- ====================================== --> <servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- 可以自定义servlet.xml配置文件的位置和名称,默认为WEB-INF目录下,名称为[<servlet-name>]-servlet.xml,如spring-servlet.xml <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring-servlet.xml</param-value> 默认 </init-param> --> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>*.jsp</url-pattern>
<!-- <url-pattern>/</url-pattern> --></servlet-mapping><!-- Spring配置 --><!-- ====================================== -->
<listener><listenerclass>org.springframework.web.context.ContextLoaderListener</listener-class></listener><!-- 指定Spring Bean的配置文件所在目录。默认配置在WEB-INF目录下 --><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:config/applicationContext.xml</param-value></context-param>配置spring-servlet.xml(spring-servlet这个名字是因为上面web.xml中<servlet-name>标签配的值为spring(<servlet-name>spring</servlet-name>),再加上“-servlet”后缀而形成的spring-servlet.xml文件名,如果改为springMVC,对应的文件名则为springMVC-servlet.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:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context <a href="http://www.springframework.org/schema/context/spring-context-3.0.xsd">http://www.springframework.org/schema/context/spring-context-3.0.xsd</a>"><!-- 启用spring mvc 注解 --><context:annotation-config /><!-- 设置使用注解的类所在的jar包 --><context:component-scan base-package="controller"></context:component-scan><!-- 完成请求和注解POJO的映射 --><bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> <!-- 对转向页面的路径解析。prefix:前缀, suffix:后缀 --><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/jsp/" p:suffix=".jsp" /></beans>
相关文章推荐
- eclipse常用的快捷键--------(真正常用的)
- Android Eclipse 导入 AS Gradle AAR 库手册
- java 反射直接获取get/set方法的写法
- Java SE 学习笔记 chapter2
- java 读写绝对路径的properties文件
- 关于Struts2 Action中get和set惹得祸。
- 文章标题 java 中文传值乱码问题
- Java基础{java概述,环境变量,注释}
- java入门学习(6)—封装,继承,多态,this,super,初始代码块
- Spring技术内幕:Spring AOP的实现原理(一)
- 详解Java编程中protected修饰符与static修饰符的作用
- Spring前台查询
- Java三大主流框架概述
- myeclipse内存溢出的问题
- Binary Tree Maximum Path Sum Java 递归解法
- Java命名规则
- 增强的接口
- javaNIO
- Java 成员函数
- Java 赋值运算符 +=