项目1学生管理选课系统-java-Tomcat-Spring-SpringMVC-Mtbatis-xml配置-第一节

目录

!web.xml!

context-param

!spring.xml!

context:component-scan

context:property-placeholder<续>

bean

!jdbc.properties!

!spring.xml!

bean<连接进入下一阶段>

tx:advice

aop:config

!web.xml!

listener

filter

servlet

!springmvc!


一级标签为当前停留所在的配置文件名字;

二级标签为阶段配置配置类名称;

顺序为程序被加载顺序,不是书写顺序。

!web.xml!

context-param

context-param<上下文参数>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring.xml</param-value> <!-- applicationContext.xml|beans.xml -->
    </context-param>

!spring.xml!

applicationContext<配置文件>

Namespaces<命名空间>(aop<面向切面编程>;beans;context;tx<配置事务>)

context:component-scan

context:component-scan<>

    <context:component-scan base-package="com.neuedu.service"></context:component-scan>

context:property-placeholder<续>

context:property-placeholder<>

    <context:property-placeholder location="classpath:jdbc.properties"/>

bean

bean<>

        <!-- 配置数据源 -->
        <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
	    <property name="user" value="${jdbc.user}"></property>
	    <property name="password" value="${jdbc.password}"></property>
		<property name="driverClass" value="${jdbc.driverClass}"></property>
		<property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>
		
		<property name="initialPoolSize"                 value="${jdbc.initialPoolSize}"></property>
		<property name="maxPoolSize" value="${jdbc.maxPoolSize}"></property>
	</bean>
	
        <!-- 整合mybatis -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource"></property>
		<property name="typeAliasesPackage" value="com.neuedu.po"></property>
	</bean>
        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
            <property name="basePackage" value="com.neuedu.mapper"></property>
            <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
        </bean>

!jdbc.properties!

jdbc.user=root
jdbc.password=123456
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.jdbcUrl=jdbc:mysql://localhost:3306/course

jdbc.initialPoolSize=5
jdbc.maxPoolSize=20

!spring.xml!

bean<连接进入下一阶段,缩写为,续>

bean<>

    <!-- 声明式事务管理 -->
	
    <!-- 配置事务管理器 -->
    <bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>

tx:advice

tx:advice<>

    <!-- 配置事务的属性-->
    <tx:advice id="txadvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="get*" read-only="true"/>
            <tx:method name="save*" propagation="REQUIRES_NEW"/>
            <tx:method name="update*" propagation="REQUIRES_NEW"/>
            <tx:method name="delete*" propagation="REQUIRES_NEW"/>	
            <tx:method name="*"/>		
        </tx:attributes>
    </tx:advice>

aop:config

aop:config<>

	<aop:config>
		<aop:pointcut expression="execution(* com.neuedu.service..*.*(..))" id="myPointcut"/>
		<aop:advisor advice-ref="txadvice" pointcut-ref="myPointcut"/>
	</aop:config>

!web.xml!

listener

listener<监听器>

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

filter

filter<过滤器>

    <filter>
	<filter-name>characterEncoding</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>characterEncoding</filter-name>
	<url-pattern>/*</url-pattern>
    </filter-mapping>

servlet

servlet<springmvc前端控制器>

    <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:springmvc.xml</param-value>
	</init-param>
	<load-on-startup>1</load-on-startup>
    </servlet>

    <!-- Map all requests to the DispatcherServlet for handling -->
    <servlet-mapping>
	<servlet-name>springmvc</servlet-name>
	<url-pattern>/</url-pattern>
    </servlet-mapping>

!springmvc!

Namespaces<命名空间>(beans;context;mvc)

    <context:component-scan base-package="com.neuedu.controller"></context:component-scan>
	
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">	
	<property name="prefix" value="/WEB-INF/views/"></property>
	<property name="suffix" value=".jsp"></property>
    </bean>
	
    <mvc:annotation-driven>
	<mvc:message-converters>
	    <bean class="org.springframework.http.converter.StringHttpMessageConverter">
	        <property name="supportedMediaTypes">
		    <list>
		        <value>text/plain;charset=utf-8</value>
			<value>text/html;charset=UTF-8</value>
		    </list>
		</property>
	    </bean>
	</mvc:message-converters>
    </mvc:annotation-driven>
    
    <!-- 
	映射静态资源
    -->
    <mvc:interceptors>
	<mvc:interceptor>
	     <mvc:mapping path="/**"/>
	     <mvc:exclude-mapping path="/static/**"/>
	     <mvc:exclude-mapping path="/login/**"/>
	         <bean id="check" class="com.neuedu.interceptor.CheckInterceptor"></bean>
        </mvc:interceptor>
    </mvc:interceptors>
	 
    <mvc:resources location="/static/" mapping="/static/**"></mvc:resources>

    <bean id="multipartResolver"
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
	<property name="maxUploadSize" value="5000000"></property>
	<property name="defaultEncoding" value="utf-8"></property>	 
    </bean>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值