<context:component-scan base-package="com.qianfeng.service"/>
<!--配置-->
<context:property-placeholder location="classpath:db.properties"></context:property-placeholder>
<!--配置数据库的连接池-->
<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource">
<property name="driverClassName" value="${driver}"/>
<property name="jdbcUrl" value="${url}"/>
<property name="username" value="${user}"/>
<property name="password" value="${pass}"/>
</bean>
<!--配置sqlsession的工厂交给spring,实现spring的接口-->
<bean id="sf" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<!--加载mybatis.xml-->
<property name="configLocation" value="classpath:mybatis.xml"/>
</bean>
<!--配置生成dao层的接口实现类,package方式必须要接口名和实现类名一致-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.qianfeng.dao"/>
</bean>
<!--配置jdbc的事务-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!--给service层增强通知-->
<tx:advice id="tx" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="insert*" read-only="true" propagation="REQUIRED"/>
<tx:method name="update*" read-only="true" propagation="REQUIRED"/>
<tx:method name="select*" read-only="true" propagation="REQUIRED"/>
<tx:method name="delete*" read-only="true" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<!--配置给service层增强通知-->
<aop:config proxy-target-class="true">
<aop:pointcut id="pt" expression="execution(* com.qianfeng.service.*.*(..))"/>
<aop:advisor advice-ref="tx" pointcut-ref="pt"/>
</aop:config>
mybatis.xml
<settings>
<setting name="logImpl" value="LOG4J"/>
</settings>
<typeAliases>
<package name="com.qianfeng.entity"/>
</typeAliases>
</configuration>
spring-mvc.xml
<context:component-scan base-package="com.qianfeng.controller"/>
<!--配置注解驱动-->
<mvc:annotation-driven/>
<!--配置处理静态资源-->
<mvc:default-servlet-handler/>
<!--配置视图解析器-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".jsp"/>
</bean>
二、/和/*和**的区别
/不会拦截.jsp和.html后缀的,会拦截.js、.css、.img的资源
/*会拦截所有包括路径类型和有后缀的类型
**是目录级别,可以有多级目录