容器配置文件大全——applicationContext.xml+web.xml

1、application.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:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        https://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        https://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/aop
        https://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx
        https://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/mvc
        https://www.springframework.org/schema/mvc/spring-mvc.xsd">
        
        
	<!-- <bean id="stuService" class="com.createblue.service.StudentService"></bean>
	
	<bean class="com.createblue.service.StudentController" >
		<property  name ="ss" ref="stuService"></property>
	</bean> -->
	
	<!--包扫描  -->
	<context:component-scan base-package="com.createblue"></context:component-scan>
	<!--自动代理-->
	<aop:aspectj-autoproxy></aop:aspectj-autoproxy>
	
	<!--mvc组件  -->
	<mvc:annotation-driven></mvc:annotation-driven>
	
	<!--文件处理  -->
	<mvc:default-servlet-handler/>
	
	<!--解析属性配置文件  -->
	<context:property-placeholder location="classpath:res.properties"/>
	<!--映射——*用于一级目录下的内容、**无限递归  -->
	<mvc:resources location="/WEB-INF/img/" mapping="/hell/**"></mvc:resources>
	<mvc:resources location="file:F:\hello\" mapping="/hello/**"></mvc:resources>
	
	
	<!-- JDBC -->
	<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
	    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
	    <property name="url" value="jdbc:mysql://localhost:3306/cbmv?useSSL=false" />
	    <property name="username" value="root" />
	    <property name="password" value="root" />
	</bean>
	<bean class="org.springframework.jdbc.core.JdbcTemplate">
		<property name="dataSource" ref="dataSource"></property>
	</bean>
	
	<!-- 事务管理 -->
	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource"></property>
	</bean>
	<tx:annotation-driven transaction-manager="transactionManager" />
	
	<!--配置前后缀的定义  -->
	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/WEB-INF/jsp/"></property>
		<property name="suffix" value=".jsp"></property>
	</bean>
	
	<!--文件上传  -->
	<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
		 <property name="defaultEncoding" value="UTF-8" /> <!--设置字符集  -->
		 <property name="maxUploadSize" value="2097152" /> <!--上传文件的大小  -->
  	</bean>
  	
  	<!--拦截器  -->
  	<mvc:interceptors>
  		<mvc:interceptor>
  			<!--拦截所有  -->
  			<mvc:mapping path="/**"/>
  			<!--不拦截  -->
  			<mvc:exclude-mapping path="/first"/>
  			<!--拦截的类  -->
  			<bean class="com.createblue.service.MyInterceptor"></bean>
  		</mvc:interceptor>
  	</mvc:interceptors>
</beans>

2、web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>FirstJspProject</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>SpringMvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
    	<param-name>contextConfigLocation</param-name>
    	<param-value>classpath:application.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>SpringMvc</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
  <!-- 第一种,使用*.do方式 -->
  <!--第二种,自定义一种  -->
  <servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>/img/*</url-pattern>
  </servlet-mapping>
  
</web-app>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值