搭建web项目之后,进行配置文件的填充,步骤:
1. 先 进行 web.xml的配置
2. web.xml 中要加载spring配置,所以紧接着添加spring的相关配置
3. 要进行数据库的操作,那么可以先建spring-dao.xml,进而添加mybatis的配置文件
4. 因为我们要用到dubbo构建服务,添加dubbo相关的配置文件spring-service.xml
5. 事务的配置spring-tx.xml(这个可以用到的时候在配置)
6. 额外的配置,日志log4j.properties
7. 每次搭建完模块后,对模块进行安装测试 命令 mvn -U clean install
上传git创建gitignore文件
*.iml
.idea/
*.ipr
*.iws
.idea_modules/
target/
*.project
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
数据库连接
jdbc
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://数据库地址:3306/数据库名?characterEncoding=utf-8
jdbc.username=root
jdbc.password=root
指定数据库类型
<?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>
< plugins>
< plugin interceptor = " com.github.pagehelper.PageHelper" >
< property name = " dialect" value = " mysql" />
</ plugin>
</ plugins>
</ configuration>
将dao层交由spring框架管理
<?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.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd" >
< context: property-placeholder location = " classpath:jdbc.properties" />
< bean id = " dataSource"
class = " com.alibaba.druid.pool.DruidDataSource" destroy-method = " close" >
< property name = " username" value = " ${jdbc.username}" />
< property name = " password" value = " ${jdbc.password}" />
< property name = " driverClassName" value = " ${jdbc.driver}" />
< property name = " url" value = " ${jdbc.url}" />
</ bean>
< bean id = " sqlSessionFactory" class = " org.mybatis.spring.SqlSessionFactoryBean" >
< property name = " dataSource" ref = " dataSource" />
< property name = " configLocation" value = " classpath:SqlMapConfig.xml" />
</ bean>
< bean class = " org.mybatis.spring.mapper.MapperScannerConfigurer" >
< property name = " basePackage" value = " com.itheima.dao" />
</ bean>
</ beans>
Service层为生产者,上传到zookeeper中
<?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: dubbo= " http://code.alibabatech.com/schema/dubbo"
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.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd" >
< dubbo: application name = " health_service_provider" />
< dubbo: protocol name = " dubbo" port = " 20887" />
< dubbo: registry address = " zookeeper://127.0.0.1:2181" />
< dubbo: annotation package = " com.itheima.service" />
< import resource = " applicationContext-redis.xml" />
</ beans>
开启事务(事务管理)
<?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"
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.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd" >
< bean id = " transactionManager"
class = " org.springframework.jdbc.datasource.DataSourceTransactionManager" >
< property name = " dataSource" ref = " dataSource" />
</ bean>
< tx: annotation-driven transaction-manager = " transactionManager"
proxy-target-class = " true" />
</ beans>
定时任务组件
<?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: dubbo= " http://code.alibabatech.com/schema/dubbo"
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.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd" >
< context: annotation-config/>
< bean id = " clearImgJob" class = " com.itheima.jobs.ClearImgJob" />
< bean id = " jobDetail"
class = " org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" >
< property name = " targetObject" ref = " clearImgJob" />
< property name = " targetMethod" value = " clearImg" />
</ bean>
< bean id = " myTrigger" class = " org.springframework.scheduling.quartz.CronTriggerFactoryBean" >
< property name = " jobDetail" ref = " jobDetail" />
< property name = " cronExpression" >
< value> 0 0/10 * * * ?</ value>
</ property>
</ bean>
< bean id = " scheduler" class = " org.springframework.scheduling.quartz.SchedulerFactoryBean" >
< property name = " triggers" >
< list>
< ref bean = " myTrigger" />
</ list>
</ property>
</ bean>
</ beans>
redis配置文件
properties文件
#最大分配的对象数
redis.pool.maxActive=200
#最大能够保持idel状态的对象数
redis.pool.maxIdle=50
redis.pool.minIdle=10
redis.pool.maxWaitMillis=20000
#当池内没有返回对象时,最大等待时间
redis.pool.maxWait=300
#格式:redis://:[密码]@[服务器地址]:[端口]/[db index]
#redis.uri = redis://:12345@127.0.0.1:6379/0
redis.host = 127.0.0.1
redis.port = 6379
redis.timeout = 30000
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: p= " http://www.springframework.org/schema/p"
xmlns: context= " http://www.springframework.org/schema/context"
xmlns: dubbo= " http://code.alibabatech.com/schema/dubbo"
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.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd" >
< bean id = " jedisPoolConfig" class = " redis.clients.jedis.JedisPoolConfig" >
< property name = " maxTotal" >
< value> 200</ value>
</ property>
< property name = " maxIdle" >
< value> 50</ value>
</ property>
< property name = " testOnBorrow" value = " true" />
< property name = " testOnReturn" value = " true" />
</ bean>
< bean id = " jedisPool" class = " redis.clients.jedis.JedisPool" >
< constructor-arg name = " poolConfig" ref = " jedisPoolConfig" />
< constructor-arg name = " host" value = " 127.0.0.1" />
< constructor-arg name = " port" value = " 6379" type = " int" />
< constructor-arg name = " timeout" value = " 30000" type = " int" />
</ bean>
</ beans>
log4j日志文件(properties文件)
### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.err
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
### direct messages to file mylog.log ###
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=F:\\log\\mylog.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
### set log levels - for more verbose logging change 'info' to 'debug' ###
log4j.rootLogger=debug, stdout