妻居一品19楼,海娜粉,西昌贺雪梅
ssm框架- s-spring s-spring mvc m-mybatis 就需要以下几个配置文件,放在resources文件夹下面:
db.properties 放的是数据库连接池的配置文件,有数据库jdbc的连接信息:
# jdbc jdbc.driverclass=com.mysql.jdbc.driver jdbc.connectionurl=jdbc:mysql://47.95.228.179:3306/mykidsshop?useunicode=true&characterencoding=utf-8&usessl=false jdbc.username=root jdbc.password=123 # jdbc pool jdbc.pool.init=1 jdbc.pool.minidle=3 jdbc.pool.maxactive=20 # jdbc test jdbc.testsql=select 'x' from dual #============================# #==== framework settings ====# #============================# # \u89c6\u56fe\u6587\u4ef6\u5b58\u653e\u8def\u5f84 web.view.prefix=/web-inf/views/ web.view.suffix=.jsp
mybatis-config.xml 放置的是mybatis相关的配置文件:
<?xml version="1.0" encoding="utf-8"?> <!doctype configuration public "-//mybatis.org//dtd config 3.0//en" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <!-- 全局参数 --> <settings> <!-- 打印 sql 语句 --> <setting name="logimpl" value="stdout_logging" /> <!-- 使全局的映射器启用或禁用缓存。 --> <setting name="cacheenabled" value="false"/> <!-- 全局启用或禁用延迟加载。当禁用时,所有关联对象都会即时加载。 --> <setting name="lazyloadingenabled" value="true"/> <!-- 当启用时,有延迟加载属性的对象在被调用时将会完全加载任意属性。否则,每种属性将会按需要加载。 --> <setting name="aggressivelazyloading" value="true"/> <!-- 是否允许单条 sql 返回多个数据集 (取决于驱动的兼容性) default:true --> <setting name="multipleresultsetsenabled" value="true"/> <!-- 是否可以使用列的别名 (取决于驱动的兼容性) default:true --> <setting name="usecolumnlabel" value="true"/> <!-- 允许 jdbc 生成主键。需要驱动器支持。如果设为了 true,这个设置将强制使用被生成的主键,有一些驱动器不兼容不过仍然可以执行。 default:false --> <setting name="usegeneratedkeys" value="false"/> <!-- 指定 mybatis 如何自动映射 数据基表的列 none:不映射 partial:部分 full:全部 --> <setting name="automappingbehavior" value="partial"/> <!-- 这是默认的执行类型 (simple: 简单; reuse: 执行器可能重复使用prepared statements语句;batch: 执行器可以重复执行语句和批量更新) --> <setting name="defaultexecutortype" value="simple"/> <!-- 使用驼峰命名法转换字段。 --> <setting name="mapunderscoretocamelcase" value="true"/> <!-- 设置本地缓存范围 session:就会有数据的共享 statement:语句范围 (这样就不会有数据的共享 ) defalut:session --> <setting name="localcachescope" value="session"/> <!-- 设置 jdbc 类型为空时,某些驱动程序 要指定值, default:other,插入空值时不需要指定类型 --> <setting name="jdbctypefornull" value="null"/> </settings> <plugins> <!-- com.github.pagehelper为pagehelper类所在包名 --> <plugin interceptor="com.github.pagehelper.pageinterceptor"> <!-- 使用下面的方式配置参数,后面会有所有的参数介绍 --> <property name="helperdialect" value="mysql"/> <property name="reasonable" value="true"/> </plugin> </plugins> </configuration>
spring-context.xml 放置的是关于spring的配置文件
<?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:tx="http://www.springframework.org/schema/tx" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!--开启注解扫描--> <context:annotation-config /> <!--不扫描controller注解--> <context:component-scan base-package="com.qfedu"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.controller"/> </context:component-scan> <!-- 配置事务管理器 --> <bean id="transactionmanager" class="org.springframework.jdbc.datasource.datasourcetransactionmanager"> <property name="datasource" ref="datasource"/> </bean> <!-- 开启事务注解驱动 --> <tx:annotation-driven transaction-manager="transactionmanager" /> </beans>
spring-context-druid.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/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- 加载配置属性文件 --> <context:property-placeholder ignore-unresolvable="true" location="classpath:db.properties"/> <!-- 数据源配置, 使用 druid 数据库连接池 --> <bean id="datasource" class="com.alibaba.druid.pool.druiddatasource" init-method="init" destroy-method="close"> <!-- 数据源驱动类可不写,druid默认会自动根据url识别driverclass --> <property name="driverclassname" value="${jdbc.driverclass}"/> <!-- 基本属性 url、user、password --> <property name="url" value="${jdbc.connectionurl}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> <!-- 配置初始化大小、最小、最大 --> <property name="initialsize" value="${jdbc.pool.init}"/> <property name="minidle" value="${jdbc.pool.minidle}"/> <property name="maxactive" value="${jdbc.pool.maxactive}"/> <!-- 配置获取连接等待超时的时间 --> <property name="maxwait" value="60000"/> <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 --> <property name="timebetweenevictionrunsmillis" value="60000"/> <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 --> <property name="minevictableidletimemillis" value="300000"/> <property name="validationquery" value="${jdbc.testsql}"/> <property name="testwhileidle" value="true"/> <property name="testonborrow" value="false"/> <property name="testonreturn" value="false"/> <!-- 配置监控统计拦截的filters --> <property name="filters" value="stat"/> </bean> </beans>
spring-context-mybatis.xml 放置的是spring与mybatis整合的配置文件:
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- 配置 sqlsession --> <bean id="sqlsessionfactory" class="org.mybatis.spring.sqlsessionfactorybean"> <property name="datasource" ref="datasource"/> <!-- 用于配置对应实体类所在的包,多个 package 之间可以用 ',' 号分割 --> <property name="typealiasespackage" value="com.qfedu.entity"/> <!-- 用于配置对象关系映射配置文件所在目录 --> <property name="mapperlocations" value="classpath*:/mapper/**/*.xml"/> <property name="configlocation" value="classpath:/mybatis-config.xml"></property> </bean> <!-- 扫描 mapper --> <bean class="org.mybatis.spring.mapper.mapperscannerconfigurer"> <property name="basepackage" value="com.qfedu.mapper" /> </bean> </beans>
spring-mvc.xml 配置的spring mvc的相关配置文件
<?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:mvc="http://www.springframework.org/schema/mvc" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <description>spring mvc configuration</description> <!-- 加载配置属性文件 --> <context:property-placeholder ignore-unresolvable="true" location="classpath:db.properties"/> <mvc:resources mapping="/static/**" location="/static/" cache-period="31536000"/> <!-- 使用 annotation 自动注册 bean,只扫描 @controller --> <context:component-scan base-package="com.qfedu" use-default-filters="false"> <context:include-filter type="annotation" expression="org.springframework.stereotype.controller"/> </context:component-scan> <!-- 默认的注解映射的支持 --> <mvc:annotation-driven /> <!-- 定义视图文件解析 --> <bean class="org.springframework.web.servlet.view.internalresourceviewresolver"> <property name="prefix" value="${web.view.prefix}"/> <property name="suffix" value="${web.view.suffix}"/> </bean> <!-- 静态资源映射 --> <mvc:resources mapping="/static/**" location="/static/" cache-period="31536000"/> <!--前后端分离开发,前端访问后端时的跨域问题--> <mvc:cors> <mvc:mapping path="/**" allowed-origins="*" allowed-methods="post, get, options, delete, put,patch" allowed-headers="content-type, access-control-allow-headers, authorization, x-requested-with" allow-credentials="true" /> </mvc:cors> </beans>
log4j.properties log4j日志文件的配置信息,用来打印日志
log4j.rootlogger=info, console, file log4j.appender.console=org.apache.log4j.consoleappender log4j.appender.console.layout=org.apache.log4j.patternlayout log4j.appender.console.layout.conversionpattern=%d %p [%c] - %m%n log4j.appender.file=org.apache.log4j.dailyrollingfileappender log4j.appender.file.file=logs/log.log log4j.appender.file.layout=org.apache.log4j.patternlayout log4j.appender.a3.maxfilesize=1024kb log4j.appender.a3.maxbackupindex=10 log4j.appender.file.layout.conversionpattern=%d %p [%c] - %m%n
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
新补丁让Windows 10出现死机、卡顿等 微软坐不住称正解决
Ubuntu 20.04 LTS进驻Windows子系统:只能用3年
ThinkPad正式加入:预装Linux发行版而非Win10的PC越来越多了
最新版Android 11推送!谷歌Pixel 5被曝光:支持反向充电
高度致敬Windows!开源优麒麟20.04 LTS发布:支持5年
电脑小知识:Windows 10是用什么语言写的?到底有多少行代码?
Win10 5月更新准正式版:微软引入大量新功能 系统响应速度快
Windows 10新预览版19613推送:修复任务栏图标显示异常BUG
Windows AD 报错解决:UAC File Virtualization服务启动失败 此驱动程序被阻止加载
网友评论