当前位置: 首页 > news >正文

Spring、Spring-MVC、Mybatis、Mybatis-generator整合核心配置文件记录

Spring、Spring-MVC、Mybatis、Mybatis-generator整合核心配置文件记录

文章目录

  • Spring、Spring-MVC、Mybatis、Mybatis-generator整合核心配置文件记录
    • 1. spring.xml
    • 2. spring-mvc.xml
    • 3. mybatis-config.xml
    • 4. mybaits-generator.xml
    • 5. ehcach.xml
    • 6. web.xml

Spring、Spring-MVC、Mybatis、Mybatis-generator整合核心配置xml文件记录

1. spring.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"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd"><!--引入系统配置的资源文件,多个文件使用 , 隔开--><context:property-placeholder location="classpath:dbConfig.properties"/><!--Spring自动扫描的dao与service包,自动注入这两个包下的所有--><context:component-scan base-package="com.ssm.dao,com.ssm.service"/>
</beans>

2. 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:context="http://www.springframework.org/schema/context"xmlns:p="http://www.springframework.org/schema/p"xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-4.0.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsd"><!-- 自动扫描controllers下的所有类,使其成为Spring MVC的控制器 --><context:component-scan base-package="com.ssm.controller"/><!--下面两句不加上,有时候会出现handler无法访问的问题--><!--将SpringMVC不能处理的请求交给Tomcat 这样可以访问静态资源--><mvc:default-servlet-handler/><!--能支持springMVC更高级的一些功能,JSR303校验,快捷Ajax,映射动态请求--><mvc:annotation-driven/><!--  避免IE执行Ajax时,返回的数据类型为JSON数据时出现下载文件的下载框 --><bean id="mappingJackson2HttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"><property name="supportedMediaTypes"><list><value>text/html;charset=UTF-8</value></list></property></bean><!--spring 3.1 开始AnnotationMethodHandlerAdapter与DefaultAnnotationHandlerMapping已经过时。用 RequestMappingHandlerMapping 来替换 DefaultAnnotationHandlerMapping,用 RequestMappingHandlerAdapter 来替换 AnnotationMethodHandlerAdapter--><bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"><property name="messageConverters"><list><ref bean="mappingJackson2HttpMessageConverter"></ref></list></property></bean><!--发布webservice同步接口  注意端口号不要和已有的冲突  项目启动即发布--><bean class="org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter"><property name="baseAddress" value="http://127.0.0.1:1231/"/></bean><bean id="accountSynchronousService" class="com.ssm.controller.sysManagement.AccountSynchronousService"></bean><!--视图解析器:对模型视图名称的解析,即在模型视图名称添加前缀与后缀--><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/views/" p:suffix=".jsp"/><!--配置自定义的拦截器--><!-- 当设置多个拦截器时,先按顺序调用preHandle方法,然后逆序调用每个拦截器的postHandle和afterCompletion方法 --><mvc:interceptors><!--配置拦截器(不)作用于那些请求路径--><!--<bean class="com.ssm.DefineInterceptor.LoginInterceptor"></bean>--><mvc:interceptor><!--作用于所有请求--><mvc:mapping path="/*.action"/><mvc:mapping path="/*/*.action"/><mvc:mapping path="/views/*.jsp"/><!--不作用于 URL为:“/userController/userLogin.action”的请求--><mvc:exclude-mapping path="/emp/empLogin.action"/><mvc:exclude-mapping path="/emp/ssoLogin.action"/><mvc:exclude-mapping path="/login.jsp"/><mvc:exclude-mapping path="/ssoLogin.jsp"/><bean class="com.ssm.UserDefinedInterceptor.LoginInterceptor"></bean></mvc:interceptor></mvc:interceptors><!--文件上传--><bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"><property name="defaultEncoding"><value>UTF-8</value></property><!--<property name="maxUploadSize"><value>1048576000</value>&lt;!&ndash;上传文件大小限制为1000M,1000*1024*1024&ndash;&gt;</property>--><property name="maxInMemorySize"><value>4096</value></property></bean></beans>

3. mybatis-config.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration><!--全局配置--><settings><!--开启驼峰命名规则--><setting name="mapUnderscoreToCamelCase" value="true"/><!--控制台打印SQL,带参数及结果--><setting name="logImpl" value="STDOUT_LOGGING"/></settings><typeAliases><package name="com.ssm.model"/></typeAliases><!--配置分页插件--><plugins><plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin></plugins>
</configuration>
  1. 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:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-4.0.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"><!-- 配置数据源 druid --><bean name="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"><property name="driverClassName" value="${jdbc_driverClassName}"/><property name="url" value="${jdbc_url}" /><property name="username" value="${jdbc_username}" /><property name="password" value="${jdbc_password}" /><!-- 初始化连接大小 --><property name="initialSize" value="0" /><!-- 连接池最大使用连接数量 --><property name="maxActive" value="20" /><!-- 连接池最大空闲 --><!--<property name="maxIdle" value="20" />--><!-- 连接池最小空闲 --><property name="minIdle" value="0" /><!-- 获取连接最大等待时间 --><property name="maxWait" value="60000" /><property name="validationQuery" value="${validationQuery}" /><property name="testOnBorrow" value="false" /><property name="testOnReturn" value="false" /><property name="testWhileIdle" value="true" /><!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 --><property name="timeBetweenEvictionRunsMillis" value="60000" /><!-- 配置一个连接在池中最小生存的时间,单位是毫秒 --><property name="minEvictableIdleTimeMillis" value="25200000" /><!-- 打开removeAbandoned功能 --><property name="removeAbandoned" value="true" /><!-- 1800秒,也就是30分钟 --><property name="removeAbandonedTimeout" value="1800" /><!-- 关闭abanded连接时输出错误日志 --><property name="logAbandoned" value="true" /><!-- 监控数据库 --><!-- <property name="filters" value="stat" /> --><property name="filters" value="mergeStat" /></bean><!--myBatis配置文件--><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><!--指定Mybatis全局配置文件位置--><property name="configLocation" value="classpath:mybatis-config.xml"></property><property name="dataSource" ref="dataSource"/><!-- 自动扫描entity文件,省掉Configuration.xml里面的手工配置,自动扫描mapping文件下的所有xml--><property name="mapperLocations" value="classpath:com/ssm/mappers/*/*.xml"></property></bean><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><property name="basePackage" value="com.ssm.dao"/><property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/></bean><!-- 配置一个可以执行批量的sqlSession --><bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate"><constructor-arg name="sqlSessionFactory" ref="sqlSessionFactory"></constructor-arg><constructor-arg name="executorType" value="BATCH"></constructor-arg></bean><!--配置事物管理器--><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource"/></bean><!--1.开启基于注解的事物;2.使用xml配置形式的事物(必须注意的是:推荐使用基于xml配置形式的事物)--><aop:config><!--切入点表达式,对 任意类型 service 包下及其子包中的任务方法中多个参数的方法进行事物控制--><aop:pointcut id="txPoint" expression="execution(* com.ssm.service..*(..))"/><!--配置事物增强--><aop:advisor advice-ref="transactionAdvice" pointcut-ref="txPoint"/></aop:config><!--注解方式配置事物--><!-- <tx:annotation-driven transaction-manager="transactionManager"/>--><!--配置事物增强,事物如何切入.注意【transaction-manager="transactionManager" 属性默认取值为transactionManager,可以省略,如果事物配置器id值不是transactionManager,则必须加上此属性】--><tx:advice id="transactionAdvice"><tx:attributes><!--切入点切入的所有方法都是事物方法--><tx:method name="insert*"></tx:method><tx:method name="delete*"></tx:method><tx:method name="update*"></tx:method><tx:method name="modify*"></tx:method><tx:method name="import*"></tx:method><tx:method name="export*"></tx:method><!--切入点切入以get开头的的所有方法都是只读事物方法--><tx:method name="get*" read-only="true"></tx:method><tx:method name="select*" read-only="true"></tx:method><tx:method name="find*" read-only="true"></tx:method><tx:method name="query*" read-only="true"></tx:method><tx:method name="count*" read-only="true"></tx:method></tx:attributes></tx:advice>
</beans>

4. mybaits-generator.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfigurationPUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN""http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"><generatorConfiguration><!--【注意:修改此文件者,请慎重执行,以免覆盖之前的代码】--><context id="DB2Tables" targetRuntime="MyBatis3"><!--阻止生成注释的配置--><commentGenerator><property name="suppressAllComments" value="true"/></commentGenerator><!--配置数据库连接信息--><jdbcConnection driverClass="oracle.jdbc.OracleDriver"connectionURL="jdbc:oracle:thin:@192.168.1.254:1521:orcl"userId="familyAccount"password="familyaccount"></jdbcConnection><javaTypeResolver><property name="forceBigDecimals" value="false"/></javaTypeResolver><!--指定JavaBen生成的位置  .\src指的是当前项目下的src目录下,注意:linux下使用的是./src,而windows下使用的是.\src--><javaModelGenerator targetPackage="testMBG.entity" targetProject="./src/main/java/"><property name="enableSubPackages" value="true"/><property name="trimStrings" value="true"/></javaModelGenerator><!--指定映射文件生成的位置--><sqlMapGenerator targetPackage="testMBG.mappers" targetProject="./src/main/java/"><property name="enableSubPackages" value="true"/></sqlMapGenerator><!--指定 dao 接口生成的位置,mapper接口--><javaClientGenerator type="XMLMAPPER" targetPackage="testMBG.dao" targetProject="./src/main/java/"><property name="enableSubPackages" value="true"/></javaClientGenerator><!--<table schema="DB2ADMIN" tableName="ALLTYPES" domainObjectName="Customer" ><property name="useActualColumnNames" value="true"/><generatedKey column="ID" sqlStatement="DB2" identity="true" /><columnOverride column="DATE_FIELD" property="startDate" /><ignoreColumn column="FRED" /><columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" /></table>--><!--<table tableName="tb_department" domainObjectName="Department"></table><table tableName="tb_employee" domainObjectName="Employee"></table><table tableName="tb_menu" domainObjectName="Menu"></table><table tableName="TB_ORGANIZATION" domainObjectName="Organization"></table>--><!--<table tableName="tb_com_log" domainObjectName="ComLog" enableSelectByExample="false"enableUpdateByExample="false" enableDeleteByExample="false" enableCountByExample="false"></table>--><!--文献资源库--><!-- <table tableName="TB_LITERATURE_RESOURCE" domainObjectName="LiteratureResource" enableSelectByExample="false"enableUpdateByExample="false" enableDeleteByExample="false" enableCountByExample="false"></table>&lt;!&ndash;逆向导入外网数据的表&ndash;&gt;<table tableName="V_IMPORT_LITERATURE" domainObjectName="ImportLiterature" enableSelectByExample="false"enableUpdateByExample="false" enableDeleteByExample="false" enableCountByExample="false"enableUpdateByPrimaryKey="false" enableDeleteByPrimaryKey="false"></table><table tableName="V_IMPORT_ATTACHMENT" domainObjectName="ImportAttachment" enableSelectByExample="false"enableUpdateByExample="false" enableDeleteByExample="false" enableCountByExample="false"enableUpdateByPrimaryKey="false" enableDeleteByPrimaryKey="false"></table>--><!--文献订阅--><!--<table tableName="TB_SUBSCRIBE" domainObjectName="Subscribe" enableSelectByExample="false"enableUpdateByExample="false" enableDeleteByExample="false" enableCountByExample="false"></table>--><table tableName="tb_user" domainObjectName="TbUser" enableSelectByExample="false"enableUpdateByExample="false" enableDeleteByExample="false" enableCountByExample="false"></table></context>
</generatorConfiguration>

5. ehcach.xml

<?xml version="1.0" encoding="UTF-8" ?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd" updateCheck="false"><!--java.io.tmpdir - Default temp file path 默认的 temp 文件目录maxElementsInMemory:内存中最大缓存对象数.maxElementsOnDisk:磁盘中最大缓存对象数,若是0表示无穷大.eternal:Element是否永久有效,一但设置了,timeout将不起作用.overflowToDisk:配置此属性,当内存中Element数量达到maxElementsInMemory时,Ehcache将会Element写到磁盘中timeToIdleSeconds:设置Element在失效前的允许闲置时间。仅当element不是永久有效时使用,可选属性,默认值是0, 也就是可闲置时间无穷大timeToLiveSeconds:设置Element在失效前允许存活时间。最大时间介于创建时间和失效时间之间。仅当element不是永久有效时使用,默认是0.也就是element存活时间无穷大.diskPersistent:是否缓存虚拟机重启期数据。diskExpiryThreadIntervalSeconds:磁盘失效线程运行时间间隔,默认是120秒。diskSpoolBufferSizeMB:这个参数设置DiskStore(磁盘缓存)的缓存区大小。默认是30MB。每个Cache都应该有自己的一个缓冲区.--><diskStore path="D:\\ehcache" /><defaultCache maxElementsInMemory="1000" eternal="false"timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true"maxElementsOnDisk="10000000" diskPersistent="false"diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU" />
</ehcache>

6. web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"version="4.0"><display-name>ssm</display-name><!--启动Spring  IOC 容器--><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:spring.xml,classpath:spring-mybatis.xml</param-value></context-param><!--监听配置--><listener><description>配置Spring监听器</description><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><listener><description>防止spring内存溢出监听器,可配置可不配</description><listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class></listener><!--字符编码过滤器 一定要放在其他过滤器之前--><filter><filter-name>characterEncodingFilter</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><!--spring新版本中 将请求与响应的编码分开了,所以指定一下请求与响应各自的编码:取值为true与false,默认为false--><init-param><param-name>forceRequestEncoding</param-name><param-value>true</param-value></init-param><init-param><param-name>forceResponseEncoding</param-name><param-value>true</param-value></init-param></filter><filter-mapping><filter-name>characterEncodingFilter</filter-name><url-pattern>/</url-pattern></filter-mapping><!--使用REST风格的URI 将普通的POST请求转为DELETE或PUT请求--><filter><filter-name>hiddenHttpMethodFilter</filter-name><filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class></filter><filter-mapping><filter-name>hiddenHttpMethodFilter</filter-name><url-pattern>/</url-pattern></filter-mapping><!--Spring MVC servlet配置--><servlet><description>Spring MVC servlet</description><servlet-name>dispatcherServlet</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></servlet><servlet-mapping><servlet-name>dispatcherServlet</servlet-name><!--这里指定应答以*.action结尾的请求,如果 是 / 则表示任意--><url-pattern>*.action</url-pattern></servlet-mapping><!-- druid监控页面,使用${pageContext.request.contextPath}/druid/index.html访问 --><servlet><servlet-name>druidStatView</servlet-name><servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class></servlet><servlet-mapping><servlet-name>druidStatView</servlet-name><url-pattern>/druid/*</url-pattern></servlet-mapping><!-- 配置session超时时间,单位分钟 --><session-config><session-timeout>30</session-timeout></session-config><welcome-file-list><welcome-file>/login.jsp</welcome-file><!--<welcome-file>/index.jsp</welcome-file>--></welcome-file-list>
</web-app>

相关文章:

  • 如何发布自己的npm包
  • ​LeetCode解法汇总2182. 构造限制重复的字符串
  • 大数据技术原理及应用课实验4: NoSQL和关系数据库的操作比较
  • Java leetcode简单刷题记录3
  • 【Linux 内核源码分析】堆内存管理
  • Glass Scienttan
  • 题记(22)--计算表达式
  • Unity中实现捏脸系统
  • HCIA-HarmonyOS设备开发认证-HarmonyOS简介
  • 大模型学习之书生·浦语大模型6——基于OpenCompass大模型评测
  • 安卓Spinner文字看不清
  • 基于yolov5-master和pyqt5的森林火灾监测软件
  • Webpack5入门到原理2:基本使用
  • System.Data.SqlClient.SqlException:“在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误
  • Flash读取数据库中的数据
  • [分享]iOS开发-关于在xcode中引用文件夹右边出现问号的解决办法
  • 「面试题」如何实现一个圣杯布局?
  • 【翻译】Mashape是如何管理15000个API和微服务的(三)
  • C++回声服务器_9-epoll边缘触发模式版本服务器
  • CSS 专业技巧
  • css属性的继承、初识值、计算值、当前值、应用值
  • express + mock 让前后台并行开发
  • IE报vuex requires a Promise polyfill in this browser问题解决
  • Java 9 被无情抛弃,Java 8 直接升级到 Java 10!!
  • JavaScript工作原理(五):深入了解WebSockets,HTTP/2和SSE,以及如何选择
  • JS字符串转数字方法总结
  • macOS 中 shell 创建文件夹及文件并 VS Code 打开
  • mac修复ab及siege安装
  • MySQL数据库运维之数据恢复
  • SpringCloud集成分布式事务LCN (一)
  • 动态魔术使用DBMS_SQL
  • 开源地图数据可视化库——mapnik
  • 利用阿里云 OSS 搭建私有 Docker 仓库
  • 两列自适应布局方案整理
  • 微信小程序填坑清单
  • 一天一个设计模式之JS实现——适配器模式
  • 继 XDL 之后,阿里妈妈开源大规模分布式图表征学习框架 Euler ...
  • 如何通过报表单元格右键控制报表跳转到不同链接地址 ...
  • 正则表达式-基础知识Review
  • !!【OpenCV学习】计算两幅图像的重叠区域
  • $$$$GB2312-80区位编码表$$$$
  • (02)Hive SQL编译成MapReduce任务的过程
  • (14)Hive调优——合并小文件
  • (cljs/run-at (JSVM. :browser) 搭建刚好可用的开发环境!)
  • (附源码)springboot社区居家养老互助服务管理平台 毕业设计 062027
  • (论文阅读23/100)Hierarchical Convolutional Features for Visual Tracking
  • (论文阅读30/100)Convolutional Pose Machines
  • (每日持续更新)jdk api之FileReader基础、应用、实战
  • (十七)devops持续集成开发——使用jenkins流水线pipeline方式发布一个微服务项目
  • (十三)Flask之特殊装饰器详解
  • (四)模仿学习-完成后台管理页面查询
  • (一)Dubbo快速入门、介绍、使用
  • (原創) 如何優化ThinkPad X61開機速度? (NB) (ThinkPad) (X61) (OS) (Windows)
  • .NET NPOI导出Excel详解
  • .net 获取url的方法