SpringMvc-+Mybatis框架配置

c#小王子 c#小王子 2022-04-07 619 Java

1 spring-mvc.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:mvc="http://www.springframework.org/schema/mvc"
       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.1.xsd
                              http://www.springframework.org/schema/context
                              http://www.springframework.org/schema/context/spring-context-3.1.xsd
                              http://www.springframework.org/schema/mvc
                              http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd ">
 
	<!-- 自动扫描该包,使SpringMVC认为包下用了@controller注解的类是控制器 -->
	<context:component-scan base-package="com.andy.manager"/>
 
	<!-- 启动SpringMVC的注解功能,完成请求和注解POJO的映射 -->
	<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"></bean>
	
	<!-- 定义跳转的文件的前后缀 ,视图模式配置-->
	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<!-- 这里的配置我的理解是自动给后面action的方法return的字符串加上前缀和后缀,变成一个 可用的url地址 -->
		<property name="prefix" value="/"/>
		<property name="suffix" value=".jsp"/>
	</bean>
	
	<!-- 配置文件上传,如果没有使用文件上传可以不用配置,当然如果不配,那么配置文件中也不必引入上传组件包 -->
	<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <!-- 默认编码 -->
        <property name="defaultEncoding" value="utf-8"/>
        <!-- 文件大小最大值 -->
        <property name="maxUploadSize" value="10485760000"/>
        <!-- 内存中的最大值 -->
        <property name="maxInMemorySize" value="40960"/>
    </bean>
 
 
    <mvc:interceptors>
        <!-- 使用bean定义一个Interceptor,直接定义在mvc:interceptors根下面的Interceptor将拦截所有的请求 -->
        <bean class="com.andy.manager.common.interceptor.CommonInterceptor"/>
    </mvc:interceptors>
 
</beans>
 

 

2  spring-mybatis.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:util="http://www.springframework.org/schema/util"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.0.xsd
       http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/util
       http://www.springframework.org/schema/util/spring-util.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
    <context:annotation-config />
    <!-- spring mvc 自动扫描注解的时候,不去扫描@Service -->
    <context:component-scan base-package="com.andy.manager">
        <!--将Controller的注解排除掉 -->
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
    </context:component-scan>
    <util:properties id="app" location="classpath:app-${env}.properties"/>
 
    <!--<bean id="dataSource_1" class="org.springframework.jndi.JndiObjectFactoryBean">-->
        <!--<property name="jndiName" value="#{app.jndiName_member}"/>-->
    <!--</bean>-->
 
    <bean id="dataSource_1" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="#{app.member_jdbcDriver}"/>
        <property name="jdbcUrl" value="#{app.member_jdbcUrl}"/>
        <property name="user" value="#{app.member_jdbcUsername}"/>
        <property name="password" value="#{app.member_jdbcPassword}"/>
        <property name="initialPoolSize" value="#{app.member_jdbcInitialPoolSize}"/>
        <property name="minPoolSize" value="#{app.member_jdbcMinPoolSize}"/>
        <property name="maxPoolSize" value="#{app.member_jdbcMaxPoolSize}"/>
        <property name="acquireIncrement" value="#{app.member_jdbcAcquireIncrement}"/>
        <property name="numHelperThreads" value="#{app.member_jdbcNumHelperThreads}"/>
        <property name="maxIdleTime" value="#{app.member_jdbcMaxIdleTime}"/>
        <property name="maxStatements" value="#{app.member_jdbcMaxStatements}"/>
        <property name="maxStatementsPerConnection" value="#{app.member_jdbcMaxStatementsPerConnection}"/>
        <property name="acquireRetryAttempts" value="#{app.member_jdbcAcquireRetryAttempts}"/>
        <property name="idleConnectionTestPeriod" value="#{app.member_jdbcIdleConnectionTestPeriod}"/>
        <property name="testConnectionOnCheckout" value="#{app.member_jdbcTestConnectionOnCheckout}"/>
    </bean>
 
	<!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
	<bean id="sqlSessionFactory_1" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource_1"/>
        <property name="configLocation" value="classpath:spring/vazh_mybatis.xml"/>
	</bean>
 
	<!-- DAO接口所在包名,Spring会自动查找其下的类 -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com. andy.manager.basinfo.mapper"/>
		<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory_1"></property>
	</bean>
 
    <!-- DAO接口所在包名,Spring会自动查找其下的类 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com. andy.manager.basinfo.vip.mapper"/>
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory_1"></property>
    </bean>
 
    <bean name="transactionManager_1" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource_1"></property>
    </bean>
    <tx:advice id="userTxAdvice_1" transaction-manager="transactionManager_1">
        <tx:attributes>
            <tx:method name="find*" propagation="SUPPORTS"/>
            <tx:method name="get*" propagation="SUPPORTS"/>
            <tx:method name="select*" propagation="SUPPORTS"/>
            <tx:method name="add*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
            <tx:method name="save*" propagation="REQUIRED" rollback-for="java.lang.RuntimeException" />
            <tx:method name="update*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
            <tx:method name="modify*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
            <tx:method name="edit*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
            <tx:method name="validate*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
            <tx:method name="del*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
            <tx:method name="remove*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
            <tx:method name="clear*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
            <tx:method name="repair*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
            <tx:method name="deleteAndRepair*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
            <tx:method name="change*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
            <tx:method name="do*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
            <tx:method name="get*" propagation="NOT_SUPPORTED" read-only="true" />
            <tx:method name="find*" propagation="NOT_SUPPORTED" read-only="true" />
            <tx:method name="load*" propagation="NOT_SUPPORTED" read-only="true" />
            <tx:method name="search*" propagation="NOT_SUPPORTED" read-only="true" />
            <tx:method name="datagrid*" propagation="NOT_SUPPORTED" read-only="true" />
            <tx:method name="*" propagation="REQUIRED" read-only="false" />
        </tx:attributes>
    </tx:advice>
 
    <aop:config>
        <!--定义在service包里的任意方法的执行:-->
        <aop:pointcut id="pc_1" expression="execution(public * com. andy.manager.basinfo.serviceimpl.*Impl.*(..))"/>
        <aop:advisor pointcut-ref="pc_1" advice-ref="userTxAdvice_1"/>
    </aop:config>
 
    <!--<bean id="dataSource2" class="org.springframework.jndi.JndiObjectFactoryBean">-->
        <!--<property name="jndiName" value="#{app.jndiName_trans}"/>-->
    <!--</bean>-->
 
    <bean id="dataSource2" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="#{app.acccore_jdbcDriver}"/>
        <property name="jdbcUrl" value="#{app.acccore_jdbcUrl}"/>
        <property name="user" value="#{app.acccore_jdbcUsername}"/>
        <property name="password" value="#{app.acccore_jdbcPassword}"/>
        <property name="initialPoolSize" value="#{app.acccore_jdbcInitialPoolSize}"/>
        <property name="minPoolSize" value="#{app.acccore_jdbcMinPoolSize}"/>
        <property name="maxPoolSize" value="#{app.acccore_jdbcMaxPoolSize}"/>
        <property name="acquireIncrement" value="#{app.acccore_jdbcAcquireIncrement}"/>
        <property name="numHelperThreads" value="#{app.acccore_jdbcNumHelperThreads}"/>
        <property name="maxIdleTime" value="#{app.acccore_jdbcMaxIdleTime}"/>
        <property name="maxStatements" value="#{app.acccore_jdbcMaxStatements}"/>
        <property name="maxStatementsPerConnection" value="#{app.acccore_jdbcMaxStatementsPerConnection}"/>
        <property name="acquireRetryAttempts" value="#{app.acccore_jdbcAcquireRetryAttempts}"/>
        <property name="idleConnectionTestPeriod" value="#{app.acccore_jdbcIdleConnectionTestPeriod}"/>
        <property name="testConnectionOnCheckout" value="#{app.acccore_jdbcTestConnectionOnCheckout}"/>
    </bean>
 
    <!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
    <bean id="sqlSessionFactory2" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource2"/>
        <property name="configLocation" value="classpath:spring/vayw_mybatis.xml"/>
    </bean>
 
    <!-- DAO接口所在包名,Spring会自动查找其下的类 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com. andy.manager.work.*.mapper"/>
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory2"></property>
    </bean>
 
    <bean name="transactionManager_2" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource2"></property>
    </bean>
    <tx:advice id="userTxAdvice_2" transaction-manager="transactionManager_2">
        <tx:attributes>
            <tx:method name="find*" propagation="SUPPORTS"/>
            <tx:method name="get*" propagation="SUPPORTS"/>
            <tx:method name="select*" propagation="SUPPORTS"/>
            <tx:method name="add*" propagation="REQUIRED" rollback-for="Exception" />
            <tx:method name="save*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
            <tx:method name="update*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
            <tx:method name="modify*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
            <tx:method name="edit*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
            <tx:method name="validate*" propagation="REQUIRED" rollback-for="Exception" />
            <tx:method name="del*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
            <tx:method name="remove*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
            <tx:method name="clear*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
            <tx:method name="repair*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
            <tx:method name="deleteAndRepair*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
            <tx:method name="change*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
            <tx:method name="do*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
            <tx:method name="get*" propagation="NOT_SUPPORTED" read-only="true" />
            <tx:method name="find*" propagation="NOT_SUPPORTED" read-only="true" />
            <tx:method name="load*" propagation="NOT_SUPPORTED" read-only="true" />
            <tx:method name="search*" propagation="NOT_SUPPORTED" read-only="true" />
            <tx:method name="datagrid*" propagation="NOT_SUPPORTED" read-only="true" />
            <tx:method name="*" propagation="REQUIRED" read-only="false" />
        </tx:attributes>
    </tx:advice>
 
    <aop:config>
        <!--定义在service包里的任意方法的执行:-->
        <aop:pointcut id="pc_2" expression="execution(public * com. andy.manager.work..serviceimpl..*Impl.*(..) )"/>
        <aop:advisor pointcut-ref="pc_2" advice-ref="userTxAdvice_2"/>
    </aop:config>
 
    <tx:annotation-driven transaction-manager="transactionManager_1"/>
    <tx:annotation-driven transaction-manager="transactionManager_2"/>
 
</beans>

 

 

3 logback.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appender name="logfile" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>../logs/mempay_cms/mempay_cms.log</File>
        <encoder>
            <Pattern>[%date] [%-5level] %logger %line --%mdc{client} [%X{TRACE_LOG_ID}] %msg%n</Pattern>
            <charset>UTF-8</charset>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>../logs/mempay_cms/mempay_cms.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
            <maxHistory>30</maxHistory>
            <TimeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>512MB</maxFileSize>
            </TimeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
    </appender>
    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <Pattern>[%date] [%-5level] %logger %line --%mdc{client} [%X{TRACE_LOG_ID}] %msg%n</Pattern>
        </encoder>
    </appender>
    <logger name="com.ibatis" level="INFO"/>
    <logger name="org.springframework" level="INFO"/>
    <logger name="java.sql.PreparedStatement" level="INFO"/>
    <logger name="org.springframework.web.servlet.DispatcherServlet" level="INFO"/>
    <logger name="com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate" level="INFO"/>
    <logger name="java.sql" level="INFO"/>
    <logger name="org.apache.commons" level="INFO"/>
    <logger name="java.sql.Statement" level="INFO"/>
    <logger name="org.springframework.web.context.support.XmlWebApplicationContext" level="INFO"/>
    <logger name="com.ibatis.common.jdbc.SimpleDataSource" level="INFO"/>
    <logger name="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" level="INFO"/>
    <logger name="java.sql.ResultSet" level="INFO"/>
    <logger name="java.sql.Connection" level="INFO"/>
    <logger name="com.ibatis.common.jdbc.ScriptRunner" level="INFO"/>
 
    <root level="INFO" >
        <appender-ref ref="console"/>
        <appender-ref ref="logfile"/>
    </root>
</configuration>

 

4 web.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
	http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <!-- Spring和mybatis的配置文件 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring-mybatis.xml</param-value>
    </context-param>
 
    <filter>
        <filter-name>encodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
     <!--   <async-supported>true</async-supported>-->
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
 
    <!-- Spring监听器 -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <!-- 防止Spring内存溢出监听器 -->
    <listener>
        <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
    </listener>
 
    <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:spring-mvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
       <!-- <async-supported>true</async-supported>-->
    </servlet>
    <servlet-mapping>
        <servlet-name>SpringMVC</servlet-name>
        <!-- 此处可以可以配置成*.do,对应struts的后缀习惯 -->
        <url-pattern>*.do</url-pattern >
    </servlet-mapping>
 
    <jsp-config>
        <taglib>
            <taglib-uri>/diyTaglib</taglib-uri>
            <taglib-location>/WEB-INF/tlds/diyTaglib.tld</taglib-location>
        </taglib>
    </jsp-config>
 
    <welcome-file-list>
        <welcome-file>login.jsp</welcome-file>
    </welcome-file-list>
</web-app>

 

百度网盘链接:https://pan.baidu.com/s/1v-fbKZPS0cG7QuOzlGGeuQ

提取码:ye4h


相关文章


使用-JFreeChart来创建基于web的图表

使用-JFreeChart来创建基于web的图表

XStream使用文档

XStream使用文档

WebService发布过程及常见问题

WebService发布过程及常见问题

webpack实战入门进阶调优分享

webpack实战入门进阶调优分享

weblogic调优参数及监控指标

weblogic调优参数及监控指标

weblogic节点管理

weblogic节点管理

weblogic管理控制台概述

weblogic管理控制台概述

weblogic-部署和启动

weblogic-部署和启动

WebLogic-Server-性能及调优-调优-Java-虚拟机

Java 虚拟机(Java virtual machine,简称 JVM)是一种虚拟“执行引擎”实例,可在微处理器上执行 Java 类文件中的字节码。调整 JVM 的方式会影响 Weblogic Server 和应用程序的性能。

Velocity用户教程

Velocity是一个基于java的模板引擎(template engine)。它允许任何人仅仅简单的使用模板语言(template language)来引用由java代码定义的对象。

Velocity用户手册

Velocity 用户手册是帮助页面设计者和内容提供者认识 Velocity 和其简单而功能强大的脚本语言――Velocity 模板语言(VTL)。在手册上的许多例子,都是用 Velocity 插入动态的内容到网页上,但是所有的 VLT 例子都能应用到其他的页面和模板中。


文章热度: 166291
文章数量: 333
推荐阅读

FlashFXP绿色版网盘下载,附激活教程 1739

FlashFxp百度网盘下载链接:https://pan.baidu.com/s/1MBQ5gkZY1TCFY8A7fnZCfQ。FlashFxp是功能强大的FTP工具

Adobe Fireworks CS6 Ansifa绿色精简版网盘下载 1540

firework可以制作精美或是可以闪瞎眼的gif,这在广告领域是需要常用的,还有firework制作下logo,一些原创的图片还是很便捷的,而且fireworks用法简单,配合dw在做网站这一块往往会发挥出很强大的效果。百度网盘下载链接:https://pan.baidu.com/s/1fzIZszfy8VX6VzQBM_bdZQ

navicat for mysql中文绿色版网盘下载 1606

Navicat for Mysql是用于Mysql数据库管理的一款图形化管理软件,非常的便捷和好用,可以方便的增删改查数据库、数据表、字段、支持mysql命令,视图等等。百度网盘下载链接:https://pan.baidu.com/s/1T_tlgxzdQLtDr9TzptoWQw 提取码:y2yq

火车头采集器(旗舰版)绿色版网盘下载 1691

火车头采集器是站长常用的工具,相比于八爪鱼,简洁好用,易于配置。火车头能够轻松的抓取网页内容,并通过自带的工具对内容进行处理。站长圈想要做网站,火车头采集器是必不可少的。百度网盘链接:https://pan.baidu.com/s/1u8wUqS901HgOmucMBBOvEA

Photoshop(CS-2015-2023)绿色中文版软件下载 1805

安装文件清单(共46G)包含Window和Mac OS各个版本的安装包,从cs到cc,从绿色版到破解版,从安装文件激活工具,应有尽有,一次性打包。 Photoshop CC绿色精简版 Photoshop CS6 Mac版 Photoshop CC 2015 32位 Photoshop CC 2015 64位 Photoshop CC 2015 MAC版 Photoshop CC 2017 64位 Adobe Photoshop CC 2018 Adobe_Photoshop_CC_2018 Photoshop CC 2018 Win32 Photoshop CC 2018 Win64

知之

知之平台是全球领先的知识付费平台。提供各个领域的项目实战经验分享,提供优质的行业解决方案信息,来帮助您的工作和学习

使用指南 建议意见 用户协议 友情链接 隐私政策 Powered by NOOU ©2020 知之