spring开发需要的配置文件
1,applicationContext-dao.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:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" 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-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd"> <!-- 数据库连接池 --> <!-- 加载配置文件 --> <context:property-placeholder location="classpath:properties/*.properties" /> <!-- 数据库连接池 --> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close"> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <property name="driverClassName" value="${jdbc.driver}" /> <property name="maxActive" value="10" /> <property name="minIdle" value="5" /> </bean> <!-- 让spring管理sqlsessionfactory 使用mybatis和spring整合包中的 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 数据库连接池 --> <property name="dataSource" ref="dataSource" /> <!-- 加载mybatis的全局配置文件 --> <property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml" /> </bean> <!-- 配置mapper文件的扫描器 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="priv.lirenhe.项目简称.dao.*" /><!-- .*指代dao下的包,而不是文件java或者xml --> </bean> </beans> |
2,applicationContext-service.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:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" 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-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd"> <!-- 包扫描器,扫描@Service注解 --> <context:component-scan base-package="priv.lirenhe.项目简称.service"></context:component-scan> </beans> |
3,applicationContext-trans.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:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" 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-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd"> <!-- 事务管理器 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <!-- 数据源 --> <property name="dataSource" ref="dataSource" /> </bean> <!-- 通知 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <!-- 传播行为 --> <tx:method name="save*" propagation="REQUIRED" /><!-- "REQUIRED" 有事务就在当前事务执行,没事务就开启事务 --> <tx:method name="insert*" propagation="REQUIRED" /> <tx:method name="add*" propagation="REQUIRED" /> <tx:method name="create*" propagation="REQUIRED" /> <tx:method name="delete*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="find*" propagation="SUPPORTS" read-only="true" /><!-- "SUPPORTS" 有事务就在当前事务执行,没事务就不开启事务 --> <tx:method name="select*" propagation="SUPPORTS" read-only="true" /> <tx:method name="get*" propagation="SUPPORTS" read-only="true" /> </tx:attributes> </tx:advice> <!-- 切面 --> <aop:config> <aop:advisor advice-ref="txAdvice" pointcut="execution(* priv.lirenhe.项目简称.service.impl.*.*(..))" /><!-- 第一个*:任意返回值 第二个*:任意返回包 第三个*:任意方法名,(..):任意参数--> </aop:config> </beans> |
4,springmvc.xml
<?xml version="1.0" encoding="UTF-8"?> <!-- 必须有带mvc的 --> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" 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/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- 配置包扫描器 --> <context:component-scan base-package="priv.lirenhe.项目简称.controller"></context:component-scan> <!-- 配置注解驱动 --> <mvc:annotation-driven/> <!-- 视图解析器 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean> </beans> |
5,db.properties
jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/数据库名?characterEncoding=utf-8 jdbc.username=root jdbc.password=123 |
6,sqlMapConfig.xml
<?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> <setting name="cacheEnabled" value="true" /> <setting name="lazyLoadingEnabled" value="true" /> <setting name="multipleResultSetsEnabled" value="true" /> <setting name="useColumnLabel" value="true" /> <setting name="useGeneratedKeys" value="false" /> <setting name="autoMappingBehavior" value="PARTIAL" /> <setting name="autoMappingUnknownColumnBehavior" value="WARNING" /> <setting name="defaultExecutorType" value="SIMPLE" /> <setting name="defaultStatementTimeout" value="100" /> <setting name="defaultFetchSize" value="100" /> <setting name="safeRowBoundsEnabled" value="false" /> <setting name="mapUnderscoreToCamelCase" value="false" /> <setting name="localCacheScope" value="SESSION" /> <setting name="jdbcTypeForNull" value="OTHER" /> <setting name="lazyLoadTriggerMethods" value="equals,clone,hashCode,toString" /> <setting name="logImpl" value="SLF4J" /> <!-- 打印查询语句 --> <!-- <setting name="logImpl" value="STDOUT_LOGGING" /> --> </settings> </configuration> |
7,log4j.properties:
### Log4j\u914D\u7F6E ### ### \u4E0ESpring\u7ED3\u5408\u9700\u8981\u5728web.xml\u4E2D\u6307\u5B9A\u6B64\u6587\u4EF6\u4F4D\u7F6E\uFF0C\u5E76\u6DFB\u52A0\u76D1\u542C\u5668 ### #\u5B9A\u4E49log4j\u7684\u8F93\u51FA\u7EA7\u522B\u548C\u8F93\u51FA\u76EE\u7684\u5730\uFF08\u76EE\u7684\u5730\u53EF\u4EE5\u81EA\u5B9A\u4E49\u540D\u79F0\uFF0C\u548C\u540E\u9762\u7684\u5BF9\u5E94\uFF09 #[ level ] , appenderName1 , appenderName2 log4j.rootLogger=DEBUG,console,file #-----------------------------------# #1 \u5B9A\u4E49\u65E5\u5FD7\u8F93\u51FA\u76EE\u7684\u5730\u4E3A\u63A7\u5236\u53F0 log4j.appender.console = org.apache.log4j.ConsoleAppender log4j.appender.console.Target = System.out log4j.appender.console.Threshold=DEBUG ####\u53EF\u4EE5\u7075\u6D3B\u5730\u6307\u5B9A\u65E5\u5FD7\u8F93\u51FA\u683C\u5F0F\uFF0C\u4E0B\u9762\u4E00\u884C\u662F\u6307\u5B9A\u5177\u4F53\u7684\u683C\u5F0F ### #%c: \u8F93\u51FA\u65E5\u5FD7\u4FE1\u606F\u6240\u5C5E\u7684\u7C7B\u76EE\uFF0C\u901A\u5E38\u5C31\u662F\u6240\u5728\u7C7B\u7684\u5168\u540D #%m: \u8F93\u51FA\u4EE3\u7801\u4E2D\u6307\u5B9A\u7684\u6D88\u606F,\u4EA7\u751F\u7684\u65E5\u5FD7\u5177\u4F53\u4FE1\u606F #%n: \u8F93\u51FA\u4E00\u4E2A\u56DE\u8F66\u6362\u884C\u7B26\uFF0CWindows\u5E73\u53F0\u4E3A"/r/n"\uFF0CUnix\u5E73\u53F0\u4E3A"/n"\u8F93\u51FA\u65E5\u5FD7\u4FE1\u606F\u6362\u884C log4j.appender.console.layout = org.apache.log4j.PatternLayout log4j.appender.console.layout.ConversionPattern=[%c]-%m%n #-----------------------------------# #2 \u6587\u4EF6\u5927\u5C0F\u5230\u8FBE\u6307\u5B9A\u5C3A\u5BF8\u7684\u65F6\u5019\u4EA7\u751F\u4E00\u4E2A\u65B0\u7684\u6587\u4EF6 log4j.appender.file = org.apache.log4j.RollingFileAppender #\u65E5\u5FD7\u6587\u4EF6\u8F93\u51FA\u76EE\u5F55 log4j.appender.file.File=log/tibet.log #\u5B9A\u4E49\u6587\u4EF6\u6700\u5927\u5927\u5C0F log4j.appender.file.MaxFileSize=10mb ###\u8F93\u51FA\u65E5\u5FD7\u4FE1\u606F### #\u6700\u4F4E\u7EA7\u522B log4j.appender.file.Threshold=ERROR log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=[%p][%d{yy-MM-dd}][%c]%m%n #4 mybatis \u663E\u793ASQL\u8BED\u53E5\u90E8\u5206 log4j.logger.org.mybatis=DEBUG #log4j.logger.cn.tibet.cas.dao=DEBUG #log4j.logger.org.mybatis.common.jdbc.SimpleDataSource=DEBUG# #log4j.logger.org.mybatis.common.jdbc.ScriptRunner=DEBUG# #log4j.logger.org.mybatis.sqlmap.engine.impl.SqlMapClientDelegate=DEBUG# #log4j.logger.java.sql.Connection=DEBUG log4j.logger.java.sql=DEBUG log4j.logger.java.sql.Statement=DEBUG log4j.logger.java.sql.ResultSet=DEBUG log4j.logger.java.sql.PreparedStatement=DEBUG |
8,applicationContext_quartz.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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <!-- 要调用的工作类 --> <bean id="Compare" class="具体调用的类.Compare"></bean> <!-- 定义调用对象和调用对象的方法 doTask--> <bean id="doTask_Compare" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <!-- 调用的类 --> <property name="targetObject"> <ref bean="Compare"/> </property> <!-- 调用类中的方法 --> <property name="targetMethod"> <value>toCompare</value> </property> </bean> <!-- 定义触发时间 doTime --> <bean id="doTime01" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> <property name="jobDetail"> <ref bean="doTask_Compare"/> </property> <!-- cron表达式 --> <property name="cronExpression"> <!-- 每天凌晨1点执行一次--> <value>00 30 00 * * ?</value><!-- 00 0/30 * * * ? --> </property> </bean> <!-- <bean id="doTime02" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> <property name="jobDetail"> <ref bean="doTask_Compare"/> </property> cron表达式 <property name="cronExpression"> 每隔10秒执行一次 <value>00 0/30 * * * ?</value>00 30 12 * * ? </property> </bean> --> <!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序 --> <bean id="startQuertz" lazy-init="true" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref bean="doTime01"/> <!-- <ref bean="doTime02"/> --> </list> </property> </bean> </beans> |
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" > <generatorConfiguration> <classPathEntry location="E:\WorkSpace04\项目名\webapp\WEB-INF\lib\mysql-connector-java-5.1.30.jar" /> <context id="MySQL"> <commentGenerator> <property name="suppressDate" value="true" /> <property name="suppressAllComments" value="true" /> </commentGenerator> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://" userId="" password="" /> <javaModelGenerator targetPackage="domain的所在包domain.mysql" targetProject="项目名" /> <sqlMapGenerator targetPackage="mapper文件生成放到的路径.dao.mysql.mapper" targetProject="项目名" /> <javaClientGenerator targetPackage=".dao.mysql" implementationPackage="dao.mysql.impl" targetProject="项目名" type="XMLMAPPER" /> <table schema="schema名" tableName="表名" domainObjectName="pojo类名" enableDeleteByExample="false" enableDeleteByPrimaryKey="false" enableInsert="false" enableUpdateByExample="false" enableUpdateByPrimaryKey="false"> <columnOverride column="DOCID" property="docId" /> <columnOverride column="UUID" property="uuid" /> <columnOverride column="DOCTITLE" property="docTitle" /> <columnOverride column="DOCHTMLCON" property="docHtmlContent" /> <columnOverride column="PAGE_TIME" property="pageTime" /> <columnOverride column="DOCCHANNEL" property="docChannel" /> <columnOverride column="AREA" property="area" /> <columnOverride column="PROVINCE" property="province" /> <columnOverride column="CITY" property="city" /> <columnOverride column="DISTRICT" property="district" /> <columnOverride column="INFO_TYPE" property="infoType" /> <columnOverride column="INDUSTRY" property="industry" /> <columnOverride column="DOCVERSION" property="docVersion" /> <columnOverride column="DOCTYPE" property="docType" /> <columnOverride column="DOCSOURCE" property="docSource" /> <columnOverride column="DOCSECURITY" property="docSecurity" /> <columnOverride column="DOCSTATUS" property="docStatus" /> <columnOverride column="DOCKEYWORDS" property="docKeywords" /> <columnOverride column="DOCRELWORDS" property="docRelwords" /> <columnOverride column="CRUSER" property="crUser" /> <columnOverride column="CRTIME" property="crTime" /> <columnOverride column="TEMPLATEID" property="templateId" /> <columnOverride column="DOCNO" property="docNo" /> <columnOverride column="HITSCOUNT" property="hitsCount" /> <columnOverride column="OPERTIME" property="operTime" /> <columnOverride column="OPERUSER" property="operUser" /> <columnOverride column="SITEID" property="siteId" /> <columnOverride column="PUBLISHTIME" property="publishTime" /> <columnOverride column="DOWNSCOUNT" property="downsCount" /> <columnOverride column="AUDITSTATUS" property="auditStatus" /> <columnOverride column="AUDITDESC" property="auditDesc" /> <columnOverride column="AUDITTIME" property="auditTime" /> <columnOverride column="WEB_SOURCE_NO" property="webSourceNo" /> <columnOverride column="WEB_SOURCE_NAME" property="webSourceName" /> <columnOverride column="INFO_SOURCE" property="infoSource" /> <columnOverride column="PAGE_ATTACHMENTS" property="pageAttachments" /> <columnOverride column="QSTATUS" property="qStatus" /> <columnOverride column="QCODES" property="qCodes" /> <columnOverride column="ISDI" property="isdi" /> <columnOverride column="ISGC" property="isgc" /> <columnOverride column="BAGENCY" property="bAgency" /> <columnOverride column="NAME" property="name" /> <columnOverride column="QTYPE" property="qType" /> <columnOverride column="EXPIRY_DATE" property="expiryDate" /> <columnOverride column="QRANGE" property="qRange" /> <columnOverride column="RECORD_ID" property="recordId" /> <columnOverride column="SEAL_NO" property="sealNo" /> <columnOverride column="ID_NO" property="idNo" /> <columnOverride column="CSTATUS" property="cStatus" /> </table> </context> </generatorConfiguration> |