我自己理解的spring

XML配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
         http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.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 http://www.springframework.org/schema/context/spring-context-3.0.xsd
           http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd"
       xmlns:p="http://www.springframework.org/schema/p">
<!--指定要扫哪些包-->
<context:component-scan base-package="com.qd"/>
<!--主持注解的方式-->
 <context:annotation-config/>

数据库链接

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

<!-- 数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <property name="driverClass" value="${jdbc.asms.driverClassName}"/>
    <property name="jdbcUrl" value="${jdbc.asms.url}"/>
    <property name="user" value="${jdbc.asms.username}"/>
    <property name="password" value="${jdbc.asms.password}"/>
    <property name="initialPoolSize" value="10"/>
    <property name="minPoolSize" value="${jdbc.asms.minPoolSize}"/>
    <property name="maxPoolSize" value="${jdbc.asms.maxPoolSize}"/>
</bean>
<!-- 配置jdbc模板对象 -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    <property name="dataSource" ref="dataSource"/>
</bean>

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource"/>
</bean>
数据库源文件:db.properties
jdbc.asms.driverClassName = com.mysql.jdbc.Driver
#jdbc.url =jdbc:oracle:thin:@localhost:1521:orcl
jdbc.asms.url= jdbc:mysql://localhost:3306/spring_test?useUnicode=true&characterEncoding=utf-8
jdbc.asms.username = root
jdbc.asms.password =root
jdbc.asms.minPoolSize=5
jdbc.asms.maxPoolSize=10
<!--开启事务注解-->
<tx:annotation-driven transaction-manager="transactionManager"/>
<!--通过这个注解就替换掉了XML配置里面的 处理器映射器  处理器适配器-->
<mvc:annotation-driven/>

配置默认处理器和视图解析器

<mvc:default-servlet-handler/>
<mvc:resources mapping="/jsp/**" location="/jsp/"/>

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix">
        <value>/jsp</value>
    </property>
    <property name="suffix">
        <value>.jsp</value>
    </property>
</bean>

配置拦截器

<mvc:interceptors>
    <mvc:interceptor>
        <mvc:mapping path="/user/userinfoget"/>
            <bean class="com.springmvc.MyHandlerInterceptor">
                <property name="whiteList" value="abc"></property>
            </bean>
    </mvc:interceptor>
</mvc:interceptors>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值