项目使用IDEA进行开发

一个分布式项目基本需要的模块。

用到的技术spring+springmvc+mybatis+dubbo +mysql+redis

01模块名字:p2p-parent

作为父模块,对其他模块进行管理。

1,idea新建空项目,设置项目保存位置。

2,选择新建模块,选择maven项目类型,不选择具体的模板,建出来是一个有maven基本结构的项目,这个项目作为父模块,可以起名为:xxx(项目名)-parent。

3,修改配置文件,在配置文件添加节点packaging,文本内容为pom:

<packaging>pom</packaging>

4,删除src目录,parent项目不需要src目录。

5,配置文件内容:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>com.bjpowernode.p2p</groupId>
<artifactId>p2p-parent</artifactId>
<version>1.0.0</version> <!---->
<packaging>pom</packaging> <properties>
<!--自定义标称名称-->
<spring-version>4.3.9.RELEASE</spring-version>
<servlet-api-version>3.1.0</servlet-api-version>
<jstl-api-version>1.2</jstl-api-version>
<taglibs-standard-version>1.2.1</taglibs-standard-version>
<mysql-connector-java-version>5.1.43</mysql-connector-java-version>
<druid-version>1.1.1</druid-version>
<mybatis-version>3.4.1</mybatis-version>
<mybatis-spring-version>1.3.0</mybatis-spring-version>
<aspectjweaver-version>1.8.9</aspectjweaver-version>
<zkclient-version>0.10</zkclient-version>
<log4j-version>2.3</log4j-version>
<spring-data-redis-version>1.8.4.RELEASE</spring-data-redis-version>
<jedis-versino>2.9.0</jedis-versino>
<dubbo-version>2.6.0</dubbo-version>
<commons-lang3-version>3.4</commons-lang3-version>
<jackson-version>2.7.3</jackson-version>
<commons-io-version>2.5</commons-io-version>
<httpclient-version>4.5.2</httpclient-version>
<fastjson-version>1.2.36</fastjson-version>
</properties> <dependencyManagement>
<dependencies>
<!--dataservice 工程依赖-->
<!-- Spring 框架依赖的 JAR 配置 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>${spring-version}</version>
</dependency>
<!-- servlet 及 jstl 标签库依赖的 JAR 配置 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servlet-api-version}</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl-api</artifactId>
<version>${jstl-api-version}</version>
</dependency>
<dependency>
<groupId>org.apache.taglibs</groupId>
<artifactId>taglibs-standard-spec</artifactId>
<version>${taglibs-standard-version}</version>
</dependency>
<dependency>
<groupId>org.apache.taglibs</groupId>
<artifactId>taglibs-standard-impl</artifactId>
<version>${taglibs-standard-version}</version>
</dependency>
<!-- MySQL 数据库连接驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql-connector-java-version}</version>
</dependency>
<!-- JDBC 数据源连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid-version}</version>
</dependency>
<!-- MyBatis 框架依赖 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis-version}</version>
</dependency>
<!-- MyBatis 与 Spring 整合依赖 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>${mybatis-spring-version}</version>
</dependency>
<!-- Spring AOP 支持 start -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectjweaver-version}</version>
</dependency>
<!-- zookeeper 客户端依赖 -->
<dependency>
<groupId>com.101tec</groupId>
<artifactId>zkclient</artifactId>
<version>${zkclient-version}</version>
</dependency>
<!-- Log4j2 依赖的 JAR 配置 -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j-version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j-version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
<version>${log4j-version}</version>
</dependency>
<!-- spring-data-redis 依赖的 JAR 配置 -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>${spring-data-redis-version}</version>
</dependency>
<!-- jedis 依赖的 JAR 配置 -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>${jedis-versino}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>${dubbo-version}</version>
<!--排除依赖冲突项-->
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- 加载 apache commons 包 start -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3-version}</version>
</dependency>
<!-- 加载 jackson 包 -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson-version}</version>
</dependency>
<!-- 文件 IO 操作包 start -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io-version}</version>
</dependency>
<!-- httpclient4.5 操作包 start -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient-version}</version>
</dependency>
<!-- 阿里巴巴 json 解析包 start -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson-version}</version>
</dependency> <dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.2</version>
<!--
provided:编译运行时生效,打包时不将该包打包
-->
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement> <build>
<plugins>
<!-- 编译插件 -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<!-- 插件的版本 -->
<version>3.5.1</version>
<!-- 编译级别 -->
<configuration>
<source>1.8</source>
<target>1.8</target>
<!-- 编码格式 -->
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build> </project>

02模块:p2p-common

存放工具类和常量类  比如日期帮助类、项目中的一些常量

新建模块,继承自parent,项目模板可以选择maven的quickstart或者不选模板,建出来后具有maven项目基本结构。

com.bjpowernode.p2p  顶级包

com.bjpowernode.p2p.common.constant   存放常量

com.bjpowernode.p2p.common.util  存放工具和帮助类

这是一个很简单的模块,其他模块会依赖该模块。

pom.xml配置文件内容:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>p2p-parent</artifactId>
<groupId>com.bjpowernode.p2p</groupId>
<version>1.0.0</version>
<relativePath>../p2p-parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion> <artifactId>p2p-common</artifactId> </project>

03模块名字:p2p-exterface

该模块是接口项目,新建模块的时候,需要继承自parent模块,同时选择继承GroupId。

选择模板,可以选择quickstart模板或者不选择模板。

dubbo推荐这种开发模式,该模板存放接口和bean、vo等。

com.bjpowernode.p2p  顶级包package

com.bjpowernode.p2p.model   存放bean的包,包名也可以是domain、beans等

com.bjpowernode.p2p.service  存放业务接口的包。

com.bjpowernode.p2p.vo    存放vo类(全称为Value Object,就是一个普通的JavaBean。一般配合DAO来使用,用于实例化对象。)

继承自parent模块,会在pom文件生成一段配置,这段配置如下,假如新建模块时没有继承自parent,可以直接在配置文件里面写上配置,达到一样的效果。

 <parent>
<artifactId>p2p-parent</artifactId>
<groupId>com.bjpowernode.p2p</groupId>
<version>1.0.0</version>
<relativePath>../p2p-parent/pom.xml</relativePath>
</parent>

具体的配置文件内容:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>p2p-parent</artifactId>
<groupId>com.bjpowernode.p2p</groupId>
<version>1.0.0</version>
<relativePath>../p2p-parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion> <artifactId>p2p-exterface</artifactId> <dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.2</version>
<!--
provided:编译运行时生效,打包时不将该包打包
-->
<scope>provided</scope>
</dependency>
</dependencies> </project>

03模块:p2p-dataservice

该模块是dubbo服务提供者。

它要去实现p2p-exterface工程的业务接口,并连接数据库实现数据的持久层

新建模块,继承自parent,模板选择maven项目webapp

com.bjpowernode.p2p  顶级包

com.bjpowernode.p2p.mapper  存放dao接口和mybatis的xml映射文件的包

com.bjpowernode.p2p.service  存放exterface的Service中接口的实现类

resources中存放配置文件

applicationContext.xml     主要:加载系统配置文件  配置扫描service包的注解  导入数据库相关配置   导入redis相关配置   导入服务提供者配置

applicationContext-datasource.xml  主要:配置数据库连接,阿里数据源 druid 连接池    MyBatis sqlSessionFactory 配置  mybatis的MapperScannerConfigurer自动装配配置、事务控制等。

applicationContext-dubbo-provider.xml  主要:服务提供者应用名称,  配置 zookeeper 注册中心   暴露具体的业务服务

applicationContext-redis.xml   主要:jedis Connection Factory    redis template definition

log4j2.xml   主要:log4j的日志配置

mybatis-configuration.xml  主要: log4j2 与 mybatis 集成,目的是打印出 sql 语句

redis.properties 主要:redis的连接数据。

WEB_INF配置文件:

web.xml  主要:spring 监听器加载 applicationContext.xml 配置文件    spring 字符过滤器

applicationContext.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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
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
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd"> <!-- 加载系统配置文件 -->
<context:property-placeholder location="classpath:*.properties" /> <!-- 扫描注解 -->
<context:component-scan base-package="com.bjpowernode.p2p.service" /> <!-- 导入数据相关配置 -->
<import resource="applicationContext-datasource.xml" />
<!-- 导入 redis 配置 -->
<import resource="applicationContext-redis.xml" />
<!-- 导入服务提供者配置 -->
<import resource="applicationContext-dubbo-provider.xml"/>
</beans>

applicationContext-datasource.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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
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
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd"> <!-- 配置数据库连接,阿里数据源 druid 连接池 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="url" value="jdbc:mysql://192.168.127.128:3306/p2p?useSSL=false&amp;useUnicode=true&amp;characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<property name="password" value="123456"/>
</bean> <!-- MyBatis sqlSessionFactory 配置 mybatis -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="classpath:mybatis-configuration.xml"/>
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- scan for mappers and let them be autowired -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.bjpowernode.p2p.mapper"/>
<property name="sqlSessionFactory" ref="sqlSessionFactory"/>
</bean> <!-- 事务相关控制 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean> <tx:annotation-driven transaction-manager="transactionManager"/> <tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!-- 对业务层所有方法添加事务,除了以 get、find、select 开始的 -->
<tx:method name="*" isolation="DEFAULT" propagation="REQUIRED" rollback-for="java.lang.Exception"/>
<!-- 查询操作没有必要开启事务,给只读事务添加一个属性 read-only -->
<tx:method name="get*" read-only="true"/>
<tx:method name="find*" read-only="true"/>
<tx:method name="select*" read-only="true"/>
<tx:method name="query*" read-only="true"/>
</tx:attributes>
</tx:advice>
<!-- Service 层事务控制 -->
<aop:config>
<aop:pointcut id="pointcut" expression="execution(* com.bjpowernode.p2p.service.**.*.*(..))"/>
<aop:advisor pointcut-ref="pointcut" advice-ref="txAdvice"/>
</aop:config>
</beans>

applicationContext-dubbo-provider.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:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> <!-- 服务提供者:应用名称 -->
<dubbo:application name="dataservice"/> <!-- 配置 zookeeper 注册中心 -->
<dubbo:registry protocol="zookeeper" address="192.168.127.128:2181"/> <!--产品业务-->
<dubbo:service interface="com.bjpowernode.p2p.service.loan.LoanInfoService" ref="loanInfoServiceImpl" version="1.0.0" timeout="15000"></dubbo:service> <!--用户业务-->
<dubbo:service interface="com.bjpowernode.p2p.service.loan.UserService" ref="userServiceImpl" version="1.0.0" timeout="15000"></dubbo:service> <!--投资业务-->
<dubbo:service interface="com.bjpowernode.p2p.service.loan.BidInfoService" ref="bidInfoServiceImpl" version="1.0.0" timeout="15000"></dubbo:service> <!--帐户业务-->
<dubbo:service interface="com.bjpowernode.p2p.service.user.FinanceAccountService" ref="financeAccountServiceImpl" version="1.0.0" timeout="15000"></dubbo:service> <!--redis业务-->
<dubbo:service interface="com.bjpowernode.p2p.service.loan.RedisService" ref="redisServiceImpl" version="1.0.0" timeout="15000"></dubbo:service> <!--收益业务-->
<dubbo:service interface="com.bjpowernode.p2p.service.loan.IncomeRecordService" ref="incomeRecordServiceImpl" version="1.0.0" timeout="15000"></dubbo:service> <!--充值业务-->
<dubbo:service interface="com.bjpowernode.p2p.service.loan.RechargeRecordService" ref="rechargeRecordServiceImpl" version="1.0.0" timeout="15000"></dubbo:service> </beans>

applicationContext-redis.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: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/context
http://www.springframework.org/schema/context/spring-context.xsd"> <!-- jedis Connection Factory -->
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:usePool="${redis.usePool}"
p:hostName="${redis.hostName}"
p:port="${redis.port}"
p:timeout="${redis.timeout}"
p:password="${redis.password}"/> <!-- redis template definition -->
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="jedisConnectionFactory"/>
</bean>
</beans>

log4j2.xml  配置文件内容:

<?xml version="1.0" encoding="UTF-8"?>
<configuration status="debug">
<appenders>
<Console name="Console" target="SYSTEM_OUT">
<ThresholdFilter level="debug" onMatch="ACCEPT"
onMismatch="ACCEPT"/>
<PatternLayout pattern="[dataservice] %d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %class{36} %L %M - %msg%xEx%n"/>
</Console>
<RollingFile name="RollingFile"
fileName="/opt/tomcat_dataservice/logs/dataservice.log"
filePattern="/opt/tomcat_dataservice/logs/$${date:yyyy-MM}/dataservice-%d{MM-dd-yyyy}-%i.log.gz">
<PatternLayout
pattern="[dataservice] %d{yyyy-MM-dd 'at' HH:mm:ss z} %-5level %class{36} %L %M - %msg%xEx%n"/>
<SizeBasedTriggeringPolicy size="100MB"/>
</RollingFile>
</appenders>
<loggers>
<logger name="com.bjpowernode.p2p.mapper"
level="debug"/>
<root level="debug">
<appender-ref ref="Console"/>
<appender-ref ref="RollingFile"/>
</root>
</loggers>
</configuration>

mybatis-configuration.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>
<!-- log4j2 与 mybatis 集成,目的是打印出 sql 语句 -->
<settings>
<setting name="logImpl" value="LOG4J2"/>
<setting name="logImpl" value="STDOUT_LOGGING"/>
</settings>
</configuration>

redis.properties配置文件主要内容:

#redis config
redis.usePool=true
redis.hostName=192.168.127.128
redis.port=6379
redis.timeout=8000
redis.password=123456

web.xml配置文件内容:

<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="dataservice" version="3.0">
<display-name>dataservice application</display-name>
<!-- spring 监听器加载 applicationContext.xml 配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- spring 字符过滤器 -->
<filter>
<filter-name>encodingFilter</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>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

04模块:p2p-web

唯一一个用户能直接访问的工程

它要负责处理用户的请求

dubbo服务的消息者

新建模块,选择maven的webapp模板,继承自parent模块

com.bjpowernode.p2p顶级包

com.bjpowernode.p2p.config   Alipay的配置类等配置信息AlipayConfig

com.bjpowernode.p2p.interceptor   拦截器,验证用户登录状态等

com.bjpowernode.p2p.web   控制器包,处理用户用户请求。

resources配置文件

applicationContext.xml  主要:导入 spring mvc 配置    导入服务提供者配置

applicationContext-dubbo-consumer.xml    主要:配置应用名称    配置注册中心   引用服务调用

applicationContext-mvc.xml  主要:dispatcherServlet 截获所有 URL 请求     spring mvc 扫描包下的 controller     配置注解驱动    配置视图解析器  配置拦截器

log4j2.xml  主要:log4j日志配置

WEB_INF下配置文件

web.xml    主要:字符过滤器,字符编码 UTF-8     Spring mvc 分发 servlet     欢迎页配置

applicationContext.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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
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
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd"> <!-- 导入 spring mvc 配置 -->
<import resource="applicationContext-mvc.xml" />
<!-- 导入服务提供者配置 -->
<import resource="applicationContext-dubbo-consumer.xml"/>
</beans>

applicationContext-dubbo-consumer.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:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> <!-- 配置应用名称 -->
<dubbo:application name="p2p"/> <!-- 配置注册中心 -->
<dubbo:registry protocol="zookeeper" address="192.168.127.128:2181"/> <!--产品业务-->
<dubbo:reference id="loanInfoService" interface="com.bjpowernode.p2p.service.loan.LoanInfoService" version="1.0.0" check="false"></dubbo:reference> <!--用户业务-->
<dubbo:reference id="userService" interface="com.bjpowernode.p2p.service.loan.UserService" version="1.0.0" check="false"></dubbo:reference> <!--投资业务-->
<dubbo:reference id="bidInfoService" interface="com.bjpowernode.p2p.service.loan.BidInfoService" version="1.0.0" check="false"></dubbo:reference> <!--帐户业务-->
<dubbo:reference id="financeAccountService" interface="com.bjpowernode.p2p.service.user.FinanceAccountService" version="1.0.0" check="false"></dubbo:reference> <!--redis业务-->
<dubbo:reference id="redisService" interface="com.bjpowernode.p2p.service.loan.RedisService" version="1.0.0" check="false"></dubbo:reference> <!--收益业务-->
<dubbo:reference id="incomeRecordService" interface="com.bjpowernode.p2p.service.loan.IncomeRecordService" version="1.0.0" check="false"></dubbo:reference> <!--充值业务-->
<dubbo:reference id="rechargeRecordService" interface="com.bjpowernode.p2p.service.loan.RechargeRecordService" version="1.0.0" timeout="15000"></dubbo:reference> </beans>

applicationContext-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:util="http://www.springframework.org/schema/util"
xmlns:aop="http://www.springframework.org/schema/aop"
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/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
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd"> <!-- dispatcherServlet 截获所有 URL 请求 -->
<mvc:default-servlet-handler/> <!-- spring mvc 扫描包下的 controller -->
<context:component-scan base-package="com.bjpowernode.p2p.web"/> <!-- 配置注解驱动 -->
<mvc:annotation-driven/> <!-- 配置视图解析器 -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"/>
<property name="suffix" value=".jsp"/>
</bean> <!--拦截器-->
<!--配置不需要拦截的地址-->
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/loan/**"/>
<mvc:exclude-mapping path="/loan/loan"/>
<mvc:exclude-mapping path="/loan/loanInfo"/>
<mvc:exclude-mapping path="/loan/checkPhone"/>
<mvc:exclude-mapping path="/loan/checkCaptcha"/>
<mvc:exclude-mapping path="/loan/register"/>
<mvc:exclude-mapping path="/loan/loadStat"/>
<mvc:exclude-mapping path="/loan/login"/>
<mvc:exclude-mapping path="/loan/messgaeCode"/>
<bean class="com.bjpowernode.p2p.interceptor.UserInterceptor"/>
</mvc:interceptor>
</mvc:interceptors> </beans>

log4j2.xml 配置文件内容:

<?xml version="1.0" encoding="UTF-8"?>
<configuration status="info">
<!--先定义所有的 appender-->
<appenders>
<!--这个输出控制台的配置-->
<Console name="Console" target="SYSTEM_OUT">
<!--控制台只输出 level 及以上级别的信息(onMatch),其他的直接拒绝(onMismatch)-->
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="ACCEPT"/>
<!--这个都知道是输出日志的格式-->
<PatternLayout pattern="[p2p] %d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %class{36} %L %M - %msg%xEx%n"/>
</Console>
<!--这个会打印出所有的信息,每次大小超过 size,则这 size 大小的日
志会自动存入按年份-月份建立的文件夹下面并进行压缩,作为存档-->
<RollingFile name="RollingFile"
fileName="/opt/tomcat_licaihost/logs/app.log"
filePattern="/opt/tomcat_licaihost/logs/$${date:yyyy-MM}/app -%d{MM-dd-yyyy}-%i.log.gz">
<PatternLayout pattern="[p2p] %d{yyyy-MM-dd 'at' HH:mm:ss z} %-5level %class{36} %L %M - %msg%xEx%n"/>
<SizeBasedTriggeringPolicy size="300MB"/>
</RollingFile>
</appenders>
<!--然后定义 logger,只有定义了 logger 并引入 appender,appender 才会生效-->
<loggers>
<!--建立一个默认的 root 的 logger-->
<root level="info">
<appender-ref ref="Console"/>
<appender-ref ref="RollingFile"/>
</root>
</loggers>
</configuration>

web.xml配置内容:

<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<!-- 应用名 -->
<display-name>p2p</display-name>
<!-- 字符过滤器,字符编码 UTF-8 -->
<filter>
<filter-name>encodingFilter</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>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Spring mvc 分发 servlet -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/index</url-pattern>
</servlet-mapping>
<!-- 欢迎页,默认进入 index controller -->
<welcome-file-list>
<welcome-file>index</welcome-file>
</welcome-file-list>
</web-app>

最新文章

  1. CSharp数据库代码生成工具
  2. SVM系列之拉格朗日对偶
  3. httpclient在抓取网页时出现速度慢的情况分析
  4. Drupal 实战
  5. 要缩小通过两个触摸点的观点(iOS)
  6. MyEclipse6.5安装SVN插件的三种方法
  7. centos redis 安装
  8. (译)通过 HTML、JS 和 Electron 创建你的第一个桌面应用
  9. C#winform程序关闭计算机的正确姿势
  10. GitHub For Beginners: Don’t Get Scared, Get Started
  11. linux 内核参数优化
  12. IP地址段遍历
  13. Ubuntu安装telent服务器时出现:apt-get:Package has no installation
  14. body标签中l的相关标签
  15. python中使用Opencv进行车牌号检测——2018.10.24
  16. HTTP1.0、HTTP1.1和HTTP2.0的区别
  17. Hibernate 常用jar包 分析
  18. Linux下安装FTP服务(Ubuntu)
  19. oracle merge into语法
  20. (简单广搜) Ice Cave -- codeforces -- 540C

热门文章

  1. 国内npm源
  2. 基于axis的WebService的案例
  3. UITableViewCell点击不能push解决方法
  4. 异常之【You have an error in your SQL syntax】
  5. vuejs与angularjs以及react的区别?
  6. pytorch基础问题
  7. 机器学习笔记:支持向量机(svm)
  8. 【Python开发】Python:itertools模块
  9. Python3图片处理头像
  10. 自然语言处理工具hanlp 1.7.3版本更新内容一览