• 00-B-springmvc分布式项目项目结构


    两个和具体业务关联不紧的模块,单独记录。有的项目可能不需要这两个模块

    05模块:p2p-pay

    该模块专门用来统一各种支付实现,比如Alipay、微信支付等

    com.bjpowernode.pay顶级包

    com.bjpowernode.pay.config  Alipay的配置类

    com.bjpowernode.pay.web  存放控制器类,接收请求并处理

    resources存放配置文件

    applicationContext.xml  主要:导入 spring mvc 配置

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

    log4j.properties   主要:log4j的配置

    WEB_INF下的配置文件:

    web.xml

    配置文件的内容:

    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" />
    </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.pay.web"/>
    
        <!-- 配置注解驱动 -->
        <mvc:annotation-driven/>
    
        <!-- 配置视图解析器 -->
        <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/"/>
            <property name="suffix" value=".jsp"/>
        </bean>
    
    
    
    </beans>

    log4j.properties的配置内容:

    log4j.rootLogger = info, stdout, file
    ### 输出到控制台 ###
    log4j.appender.stdout = org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.Target = System.out
    log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.ConversionPattern = [pay] %d{ABSOLUTE} %5p %c{1}:%L - %m%n
    
    log4j.appender.file = org.apache.log4j.DailyRollingFileAppender
    log4j.appender.file.File = /opt/pay/logs/log.log
    log4j.appender.file.Append = true
    log4j.appender.file.Threshold = debug
    log4j.appender.file.layout = org.apache.log4j.PatternLayout
    log4j.appender.file.layout.ConversionPattern = [pay] %-d{yyyy-MM-dd HH:mm:ss} [ %c{1} ] - [ %p ] %m%n

    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>pay</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>
    </web-app>

    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-pay</artifactId>
        <packaging>war</packaging>
    
        <dependencies>
    
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aop</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-core</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-beans</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-jdbc</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-tx</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-web</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-webmvc</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-oxm</artifactId>
            </dependency>
    
            <!-- servlet及jstl标签库依赖的JAR配置 -->
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>javax.servlet-api</artifactId>
            </dependency>
            <dependency>
                <groupId>javax.servlet.jsp.jstl</groupId>
                <artifactId>jstl-api</artifactId>
            </dependency>
            <dependency>
                <groupId>org.apache.taglibs</groupId>
                <artifactId>taglibs-standard-spec</artifactId>
            </dependency>
            <dependency>
                <groupId>org.apache.taglibs</groupId>
                <artifactId>taglibs-standard-impl</artifactId>
            </dependency>
    
            <!-- 加载jackson包 -->
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-core</artifactId>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-annotations</artifactId>
            </dependency>
    
            <!-- commons-logging依赖的JAR配置start -->
            <dependency>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
                <version>1.2</version>
            </dependency>
    
            <!-- Log4j的配置start -->
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>1.2.17</version>
            </dependency>
    
            <dependency>
                <groupId>com.bjpowernode.p2p</groupId>
                <artifactId>p2p-common</artifactId>
                <version>1.0.0</version>
            </dependency>
            <!--引入非本地仓库的依赖-->
            <dependency>
                <groupId>com.alipay.api</groupId>
                <artifactId>alipay-sdk-java</artifactId>
                <version>20170324180803</version>
                <scope>system</scope>
                <systemPath>${basedir}/src/main/webapp/WEB-INF/lib/alipay-sdk-java20170324180803.jar</systemPath>
            </dependency>
    
            <!--wxpay-sdk-->
            <dependency>
                <groupId>com.github.wxpay</groupId>
                <artifactId>wxpay-sdk</artifactId>
                <version>0.0.3</version>
            </dependency>
    
            <dependency>
                <groupId>com.bjpowernode</groupId>
                <artifactId>HttpClient</artifactId>
                <version>1.0.0</version>
            </dependency>
    
        </dependencies>
    
    </project>

    06模块:p2p-timer

    该模块执行一些定时的任务

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

    com.bjpowernode.p2p  顶级包

    com.bjpowernode.p2p.timer  放具体执行定时任务的类

    resources配置文件

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

    applicationContext-dubbo-consumer.xml  主要:配置应用名称   配置注册中心   引用服务提供者暴露的服务

    applicationContext-task.xml  主要:自动扫描的包名  

    log4j.properties  主要:配置log4j配置

    WEB_INF下配置文件

    web.xml

    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 task 配置 -->
        <import resource="applicationContext-task.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-task.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:aop="http://www.springframework.org/schema/aop"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xmlns:jdbc="http://www.springframework.org/schema/jdbc"
           xmlns:util="http://www.springframework.org/schema/util"
           xmlns:task="http://www.springframework.org/schema/task"
           xmlns:context="http://www.springframework.org/schema/context"
           xsi:schemaLocation="
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
                http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.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/task http://www.springframework.org/schema/task/spring-task.xsd
                http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd ">
    
        <!-- 自动扫描的包名 -->
        <context:component-scan base-package="com.bjpowernode.p2p.timer"/>
    
        <task:annotation-driven/>
    </beans>

    log4j.properties配置内容:

    log4j.rootLogger = info, stdout, file
    ### 输出到控制台 ###
    log4j.appender.stdout = org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.Target = System.out
    log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.ConversionPattern = [timer] %d{ABSOLUTE} %5p %c{1}:%L - %m%n
    
    log4j.appender.file = org.apache.log4j.DailyRollingFileAppender
    log4j.appender.file.File = /opt/task/timer/logs/log.log
    log4j.appender.file.Append = true
    log4j.appender.file.Threshold = debug
    log4j.appender.file.layout = org.apache.log4j.PatternLayout
    log4j.appender.file.layout.ConversionPattern = [timer] %-d{yyyy-MM-dd HH:mm:ss} [ %c{1} ] - [ %p ] %m%n

    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>timer 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>
    </web-app>
  • 相关阅读:
    个人所得税避税的10种方法
    营业税
    融资租赁
    会计等式
    公司公积金
    fixed语句
    自由之路
    $or操作符
    $in 操作符
    Redis 字典的实现
  • 原文地址:https://www.cnblogs.com/Tpf386/p/10988015.html
Copyright © 2020-2023  润新知