• ssm+maven+dubbo项目搭建


    第一步:整体项目zb_project的pom配置

      1 <?xml version="1.0" encoding="UTF-8"?>
      2 
      3 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      4   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      5   <modelVersion>4.0.0</modelVersion>
      6 
      7   <groupId>zb-dubboDemo</groupId>
      8   <artifactId>zb-Project</artifactId>
      9   <packaging>pom</packaging>
     10   <version>1.0-SNAPSHOT</version>
     11   <modules>
     12     <module>zb-common</module>
     13     <module>zb-Server01</module>
     14     <module>zb-web</module>
     15   </modules>
     16 
     17   <name>zb-Project</name>
     18   <url>http://maven.apache.org</url>
     19 
     20   <properties>
     21     <java.version>1.8</java.version>
     22     <java.encoding>utf-8</java.encoding>
     23     <springframework.version>4.2.4.RELEASE</springframework.version>
     24     <mybatis.version>3.3.1</mybatis.version>
     25     <mybatis-spring.version>1.2.4</mybatis-spring.version>
     26     <mysql.version>5.1.36</mysql.version>
     27     <servlet.version>3.1.0</servlet.version>
     28     <jedis.version>2.9.0</jedis.version>
     29     <redisson.version>3.5.4</redisson.version>
     30     <spring-data-redis.version>2.0.0.RELEASE</spring-data-redis.version>
     31     <spring-session-data-redis.version>1.3.1.RELEASE</spring-session-data-redis.version>
     32     <dubbo.version>2.5.5</dubbo.version>
     33     <solr.version>7.1.0</solr.version>
     34     <solr-spring-data.version>3.0.0.RELEASE</solr-spring-data.version>
     35     <nexus.url>http://123.56.78.170:8082/nexus</nexus.url>
     36   </properties>
     37 
     38   <dependencies>
     39     <!-- fastdfs -->
     40 
     41 
     42     <!-- solr -->
     43     <dependency>
     44       <groupId>org.apache.solr</groupId>
     45       <artifactId>solr-solrj</artifactId>
     46       <version>4.10.1</version>
     47     </dependency>
     48 
     49     <dependency>
     50       <groupId>org.springframework.data</groupId>
     51       <artifactId>spring-data-solr</artifactId>
     52       <version>${solr-spring-data.version}</version>
     53     </dependency>
     54 
     55 
     56     <dependency>
     57       <groupId>javax.servlet</groupId>
     58       <artifactId>jstl</artifactId>
     59       <version>1.2</version>
     60     </dependency>
     61 
     62     <dependency>
     63       <groupId>javax.servlet</groupId>
     64       <artifactId>javax.servlet-api</artifactId>
     65       <version>3.1.0</version>
     66     </dependency>
     67 
     68     <dependency>
     69       <groupId>javax.servlet.jsp</groupId>
     70       <artifactId>jsp-api</artifactId>
     71       <version>2.1</version>
     72     </dependency>
     73 
     74     <!-- mysql 驱动start -->
     75     <dependency>
     76       <groupId>mysql</groupId>
     77       <artifactId>mysql-connector-java</artifactId>
     78       <version>${mysql.version}</version>
     79     </dependency>
     80 
     81     <dependency>
     82       <groupId>org.mybatis</groupId>
     83       <artifactId>mybatis-ehcache</artifactId>
     84       <version>1.0.0</version>
     85     </dependency>
     86 
     87     <!-- mybatis分页插件 -->
     88     <dependency>
     89       <groupId>com.github.pagehelper</groupId>
     90       <artifactId>pagehelper</artifactId>
     91       <version>4.1.0</version>
     92     </dependency>
     93 
     94     <dependency>
     95       <groupId>com.alibaba</groupId>
     96       <artifactId>druid</artifactId>
     97       <version>1.0.3</version>
     98     </dependency>
     99 
    100     <dependency>
    101       <groupId>log4j</groupId>
    102       <artifactId>log4j</artifactId>
    103       <version>1.2.17</version>
    104     </dependency>
    105 
    106     <dependency>
    107       <groupId>org.slf4j</groupId>
    108       <artifactId>slf4j-log4j12</artifactId>
    109       <version>1.7.12</version>
    110     </dependency>
    111 
    112     <!-- CGLIB -->
    113     <dependency>
    114       <groupId>cglib</groupId>
    115       <artifactId>cglib-nodep</artifactId>
    116       <version>2.1_3</version>
    117     </dependency>
    118 
    119     <dependency>
    120       <groupId>junit</groupId>
    121       <artifactId>junit</artifactId>
    122       <version>4.12</version>
    123       <scope>test</scope>
    124     </dependency>
    125 
    126     <dependency>
    127       <groupId>org.json</groupId>
    128       <artifactId>json</artifactId>
    129       <version>20151123</version>
    130     </dependency>
    131 
    132     <!-- jdbc -->
    133     <dependency>
    134       <groupId>org.mybatis</groupId>
    135       <artifactId>mybatis-spring</artifactId>
    136       <version>${mybatis-spring.version}</version>
    137     </dependency>
    138 
    139     <dependency>
    140       <groupId>org.mybatis</groupId>
    141       <artifactId>mybatis</artifactId>
    142       <version>${mybatis.version}</version>
    143     </dependency>
    144     <dependency>
    145       <groupId>commons-io</groupId>
    146       <artifactId>commons-io</artifactId>
    147       <version>2.0.1</version>
    148     </dependency>
    149 
    150     <dependency>
    151       <groupId>commons-logging</groupId>
    152       <artifactId>commons-logging</artifactId>
    153       <version>1.1.3</version>
    154     </dependency>
    155 
    156     <dependency>
    157       <groupId>commons-codec</groupId>
    158       <artifactId>commons-codec</artifactId>
    159       <version>1.9</version>
    160     </dependency>
    161 
    162     <dependency>
    163       <groupId>commons-validator</groupId>
    164       <artifactId>commons-validator</artifactId>
    165       <version>1.3.1</version>
    166     </dependency>
    167 
    168     <dependency>
    169       <groupId>commons-digester</groupId>
    170       <artifactId>commons-digester</artifactId>
    171       <version>1.8</version>
    172     </dependency>
    173 
    174     <dependency>
    175       <groupId>commons-lang</groupId>
    176       <artifactId>commons-lang</artifactId>
    177       <version>2.4</version>
    178     </dependency>
    179 
    180     <dependency>
    181       <groupId>commons-beanutils</groupId>
    182       <artifactId>commons-beanutils-core</artifactId>
    183       <version>1.7.0</version>
    184     </dependency>
    185 
    186     <dependency>
    187       <groupId>commons-collections</groupId>
    188       <artifactId>commons-collections</artifactId>
    189       <version>3.2.1</version>
    190     </dependency>
    191 
    192     <dependency>
    193       <groupId>commons-fileupload</groupId>
    194       <artifactId>commons-fileupload</artifactId>
    195       <version>1.3.2</version>
    196     </dependency>
    197 
    198     <dependency>
    199       <groupId>org.apache.commons</groupId>
    200       <artifactId>commons-lang3</artifactId>
    201       <version>3.5</version>
    202     </dependency>
    203 
    204 
    205     <!-- spring -->
    206     <dependency>
    207       <groupId>org.springframework</groupId>
    208       <artifactId>spring-core</artifactId>
    209       <version>${springframework.version}</version>
    210     </dependency>
    211 
    212     <dependency>
    213       <groupId>org.springframework</groupId>
    214       <artifactId>spring-beans</artifactId>
    215       <version>${springframework.version}</version>
    216     </dependency>
    217 
    218     <dependency>
    219       <groupId>org.springframework</groupId>
    220       <artifactId>spring-context</artifactId>
    221       <version>${springframework.version}</version>
    222     </dependency>
    223 
    224     <dependency>
    225       <groupId>org.springframework</groupId>
    226       <artifactId>spring-context-support</artifactId>
    227       <version>${springframework.version}</version>
    228     </dependency>
    229 
    230     <dependency>
    231       <groupId>org.springframework</groupId>
    232       <artifactId>spring-test</artifactId>
    233       <version>${springframework.version}</version>
    234       <scope>test</scope>
    235     </dependency>
    236 
    237     <dependency>
    238       <groupId>org.springframework</groupId>
    239       <artifactId>spring-tx</artifactId>
    240       <version>${springframework.version}</version>
    241     </dependency>
    242 
    243     <dependency>
    244       <groupId>org.springframework</groupId>
    245       <artifactId>spring-web</artifactId>
    246       <version>${springframework.version}</version>
    247     </dependency>
    248 
    249     <dependency>
    250       <groupId>org.springframework</groupId>
    251       <artifactId>spring-webmvc</artifactId>
    252       <version>${springframework.version}</version>
    253     </dependency>
    254 
    255     <dependency>
    256       <groupId>org.springframework</groupId>
    257       <artifactId>spring-aspects</artifactId>
    258       <version>${springframework.version}</version>
    259     </dependency>
    260 
    261     <dependency>
    262       <groupId>org.springframework</groupId>
    263       <artifactId>spring-expression</artifactId>
    264       <version>${springframework.version}</version>
    265     </dependency>
    266 
    267     <dependency>
    268       <groupId>org.springframework</groupId>
    269       <artifactId>spring-jdbc</artifactId>
    270       <version>${springframework.version}</version>
    271     </dependency>
    272 
    273     <dependency>
    274       <groupId>aopalliance</groupId>
    275       <artifactId>aopalliance</artifactId>
    276       <version>1.0</version>
    277     </dependency>
    278 
    279     <dependency>
    280       <groupId>org.aspectj</groupId>
    281       <artifactId>aspectjrt</artifactId>
    282       <version>1.7.3</version>
    283     </dependency>
    284     <dependency>
    285       <groupId>org.javassist</groupId>
    286       <artifactId>javassist</artifactId>
    287       <version>3.20.0-GA</version>
    288     </dependency>
    289     <dependency>
    290       <groupId>org.aspectj</groupId>
    291       <artifactId>aspectjweaver</artifactId>
    292       <version>1.6.10</version>
    293       <scope>runtime</scope>
    294     </dependency>
    295 
    296     <dependency>
    297       <groupId>org.springframework</groupId>
    298       <artifactId>spring-aop</artifactId>
    299       <version>${springframework.version}</version>
    300       <exclusions>
    301         <exclusion>
    302           <groupId>commons-logging</groupId>
    303           <artifactId>commons-logging</artifactId>
    304         </exclusion>
    305       </exclusions>
    306     </dependency>
    307     <!--极光推送依赖 start-->
    308     <dependency>
    309       <groupId>cn.jpush.api</groupId>
    310       <artifactId>jpush-client</artifactId>
    311       <version>3.2.17</version>
    312     </dependency>
    313     <dependency>
    314       <groupId>cn.jpush.api</groupId>
    315       <artifactId>jiguang-common</artifactId>
    316       <version>1.0.7</version>
    317     </dependency>
    318     <!--极光推送依赖 end-->
    319     <!-- json依赖包 -->
    320     <dependency>
    321       <groupId>com.fasterxml.jackson.core</groupId>
    322       <artifactId>jackson-core</artifactId>
    323       <version>2.5.0</version>
    324     </dependency>
    325 
    326     <dependency>
    327       <groupId>com.fasterxml.jackson.core</groupId>
    328       <artifactId>jackson-databind</artifactId>
    329       <version>2.5.0</version>
    330     </dependency>
    331 
    332     <dependency>
    333       <groupId>com.fasterxml.jackson.core</groupId>
    334       <artifactId>jackson-annotations</artifactId>
    335       <version>2.5.0</version>
    336     </dependency>
    337 
    338     <dependency>
    339       <groupId>com.alibaba</groupId>
    340       <artifactId>fastjson</artifactId>
    341       <version>1.2.4</version>
    342     </dependency>
    343 
    344     <!--dom4j-->
    345     <dependency>
    346       <groupId>dom4j</groupId>
    347       <artifactId>dom4j</artifactId>
    348       <version>1.6.1</version>
    349     </dependency>
    350 
    351     <dependency>
    352       <groupId>jaxen</groupId>
    353       <artifactId>jaxen</artifactId>
    354       <version>1.1.1</version>
    355     </dependency>
    356 
    357     <dependency>
    358       <groupId>commons-httpclient</groupId>
    359       <artifactId>commons-httpclient</artifactId>
    360       <version>3.0</version>
    361     </dependency>
    362 
    363     <dependency>
    364       <groupId>org.apache.poi</groupId>
    365       <artifactId>poi</artifactId>
    366       <version>3.9</version>
    367     </dependency>
    368 
    369     <dependency>
    370       <groupId>org.apache.poi</groupId>
    371       <artifactId>poi-ooxml</artifactId>
    372       <version>3.9</version>
    373     </dependency>
    374 
    375     <dependency>
    376       <groupId>com.aliyun.oss</groupId>
    377       <artifactId>aliyun-sdk-oss</artifactId>
    378       <version>2.5.0</version>
    379     </dependency>
    380 
    381     <dependency>
    382       <groupId>eu.bitwalker</groupId>
    383       <artifactId>UserAgentUtils</artifactId>
    384       <version>1.20</version>
    385     </dependency>
    386 
    387     <!-- freemarker begin -->
    388     <dependency>
    389       <groupId>org.freemarker</groupId>
    390       <artifactId>freemarker</artifactId>
    391       <version>2.3.20</version>
    392     </dependency>
    393 
    394     <!-- Dubbo -->
    395     <dependency>
    396       <groupId>com.alibaba</groupId>
    397       <artifactId>dubbo</artifactId>
    398       <version>${dubbo.version}</version>
    399       <exclusions>
    400         <exclusion>
    401           <groupId>org.springframework</groupId>
    402           <artifactId>spring</artifactId>
    403         </exclusion>
    404         <exclusion>
    405           <groupId>org.jboss.netty</groupId>
    406           <artifactId>netty</artifactId>
    407         </exclusion>
    408       </exclusions>
    409     </dependency>
    410 
    411     <dependency>
    412       <groupId>com.101tec</groupId>
    413       <artifactId>zkclient</artifactId>
    414       <version>0.10</version>
    415       <exclusions>
    416         <exclusion>
    417           <groupId>org.slf4j</groupId>
    418           <artifactId>slf4j-log4j12</artifactId>
    419         </exclusion>
    420       </exclusions>
    421     </dependency>
    422 
    423     <dependency>
    424       <groupId>io.netty</groupId>
    425       <artifactId>netty-all</artifactId>
    426       <version>4.1.16.Final</version>
    427     </dependency>
    428 
    429     <dependency>
    430       <groupId>org.apache.zookeeper</groupId>
    431       <artifactId>zookeeper</artifactId>
    432       <version>3.4.10</version>
    433     </dependency>
    434 
    435     <dependency>
    436       <groupId>com.netflix.curator</groupId>
    437       <artifactId>curator-framework</artifactId>
    438       <version>1.3.3</version>
    439     </dependency>
    440 
    441     <!-- 缓存 -->
    442     <dependency>
    443       <groupId>redis.clients</groupId>
    444       <artifactId>jedis</artifactId>
    445       <version>${jedis.version}</version>
    446     </dependency>
    447 
    448     <dependency>
    449       <groupId>org.springframework.data</groupId>
    450       <artifactId>spring-data-redis</artifactId>
    451       <version>${spring-data-redis.version}</version>
    452     </dependency>
    453 
    454     <dependency>
    455       <groupId>org.springframework.session</groupId>
    456       <artifactId>spring-session-data-redis</artifactId>
    457       <version>${spring-session-data-redis.version}</version>
    458     </dependency>
    459 
    460     <dependency>
    461       <groupId>org.redisson</groupId>
    462       <artifactId>redisson</artifactId>
    463       <version>${redisson.version}</version>
    464     </dependency>
    465 
    466     <dependency>
    467       <groupId>org.apache.velocity</groupId>
    468       <artifactId>velocity</artifactId>
    469       <version>1.7</version>
    470     </dependency>
    471   </dependencies>
    472 
    473 
    474   <build>
    475     <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
    476       <plugins>
    477         <plugin>
    478           <artifactId>maven-clean-plugin</artifactId>
    479           <version>3.0.0</version>
    480         </plugin>
    481         <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
    482         <plugin>
    483           <artifactId>maven-resources-plugin</artifactId>
    484           <version>3.0.2</version>
    485         </plugin>
    486         <plugin>
    487           <artifactId>maven-compiler-plugin</artifactId>
    488           <version>3.7.0</version>
    489         </plugin>
    490         <plugin>
    491           <artifactId>maven-surefire-plugin</artifactId>
    492           <version>2.20.1</version>
    493         </plugin>
    494         <plugin>
    495           <artifactId>maven-jar-plugin</artifactId>
    496           <version>3.0.2</version>
    497         </plugin>
    498         <plugin>
    499           <artifactId>maven-install-plugin</artifactId>
    500           <version>2.5.2</version>
    501         </plugin>
    502         <plugin>
    503           <artifactId>maven-deploy-plugin</artifactId>
    504           <version>2.8.2</version>
    505         </plugin>
    506       </plugins>
    507     </pluginManagement>
    508   </build>
    509 </project>
    View Code

    第二步:公共工具的子项目zb-common的pom配置

    <?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>zb-Project</artifactId>
            <groupId>zb-dubboDemo</groupId>
            <version>1.0-SNAPSHOT</version>
        </parent>
        <modelVersion>4.0.0</modelVersion>
    
        <artifactId>zb-common</artifactId>
    
        <name>zb-common</name>
        <packaging>jar</packaging>
        <url>http://maven.apache.org</url>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <maven.compiler.source>1.7</maven.compiler.source>
            <maven.compiler.target>1.7</maven.compiler.target>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>3.8.1</version>
                <scope>test</scope>
            </dependency>
    
    
            <dependency>
                <groupId>commons-cli</groupId>
                <artifactId>commons-cli</artifactId>
                <version>1.2</version>
            </dependency>
            <dependency>
                <groupId>commons-io</groupId>
                <artifactId>commons-io</artifactId>
                <version>2.3</version>
            </dependency>
            <dependency>
                <groupId>org.openoffice</groupId>
                <artifactId>juh</artifactId>
                <version>3.0.1</version>
            </dependency>
            <dependency>
                <groupId>org.openoffice</groupId>
                <artifactId>jurt</artifactId>
                <version>3.0.1</version>
            </dependency>
            <dependency>
                <groupId>org.openoffice</groupId>
                <artifactId>ridl</artifactId>
                <version>3.0.1</version>
            </dependency>
            <!--<dependency>-->
            <!--<groupId>org.slf4j</groupId>-->
            <!--<artifactId>slf4j-jdk14</artifactId>-->
            <!--<version>1.5.6</version>-->
            <!--</dependency>-->
            <dependency>
                <groupId>org.openoffice</groupId>
                <artifactId>unoil</artifactId>
                <version>3.0.1</version>
            </dependency>
            <dependency>
                <groupId>com.thoughtworks.xstream</groupId>
                <artifactId>xstream</artifactId>
                <version>1.3.1</version>
            </dependency>
            <dependency>
                <groupId>com.artofsolving</groupId>
                <artifactId>jodconverter</artifactId>
                <version>2.2.1</version>
                <exclusions>
                    <exclusion>
                        <artifactId>slf4j-api</artifactId>
                        <groupId>org.slf4j</groupId>
                    </exclusion>
                </exclusions>
            </dependency>
    
        </dependencies>
    
        <build>
            <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
                <plugins>
                    <plugin>
                        <artifactId>maven-clean-plugin</artifactId>
                        <version>3.0.0</version>
                    </plugin>
                    <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
                    <plugin>
                        <artifactId>maven-resources-plugin</artifactId>
                        <version>3.0.2</version>
                    </plugin>
                    <plugin>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.7.0</version>
                    </plugin>
                    <plugin>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.20.1</version>
                    </plugin>
                    <plugin>
                        <artifactId>maven-jar-plugin</artifactId>
                        <version>3.0.2</version>
                    </plugin>
                    <plugin>
                        <artifactId>maven-install-plugin</artifactId>
                        <version>2.5.2</version>
                    </plugin>
                    <plugin>
                        <artifactId>maven-deploy-plugin</artifactId>
                        <version>2.8.2</version>
                    </plugin>
                </plugins>
            </pluginManagement>
        </build>
    </project>
    View Code

    第三布:server子项目配置

    1.server-entity(server中存放逆向工程生成的实体,mapper接口,mapper.xml)

    2.server-service(存放服务接口)

        <1.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>
        <plugins>
            <!-- com.github.pagehelper为PageHelper类所在包名 -->
            <plugin interceptor="com.github.pagehelper.PageHelper">
                <!-- 4.0.0以后版本可以不设置该参数 -->
                <property name="dialect" value="mysql"/>
                <!-- 该参数默认为false -->
                <!-- 设置为true时,会将RowBounds第一个参数offset当成pageNum页码使用 -->
                <!-- 和startPage中的pageNum效果一样-->
                <property name="offsetAsPageNum" value="true"/>
                <!-- 该参数默认为false -->
                <!-- 设置为true时,使用RowBounds分页会进行count查询 -->
                <property name="rowBoundsWithCount" value="true"/>
                <!-- 设置为true时,如果pageSize=0或者RowBounds.limit = 0就会查询出全部的结果 -->
                <!-- (相当于没有执行分页查询,但是返回结果仍然是Page类型)-->
                <property name="pageSizeZero" value="true"/>
                <!-- 3.3.0版本可用 - 分页参数合理化,默认false禁用 -->
                <!-- 启用合理化时,如果pageNum<1会查询第一页,如果pageNum>pages会查询最后一页 -->
                <!-- 禁用合理化时,如果pageNum<1或pageNum>pages会返回空数据 -->
                <property name="reasonable" value="true"/>
                <!-- 3.5.0版本可用 - 为了支持startPage(Object params)方法 -->
                <!-- 增加了一个`params`参数来配置参数映射,用于从Map或ServletRequest中取值 -->
                <!-- 可以配置pageNum,pageSize,count,pageSizeZero,reasonable,orderBy,不配置映射的用默认值 -->
                <!-- 不理解该含义的前提下,不要随便复制该配置 -->
                <property name="params" value="pageNum=pageHelperStart;pageSize=pageHelperRows;"/>
                <!-- 支持通过Mapper接口参数来传递分页参数 -->
                <property name="supportMethodsArguments" value="false"/>
                <!-- always总是返回PageInfo类型,check检查返回类型是否为PageInfo,none返回Page -->
                <property name="returnPageInfo" value="none"/>
            </plugin>
        </plugins>
    </configuration>
    View Code

       <2.log4j.properties

    log4j.rootLogger=DEBUG,stdout,A1 ,A2
    
    log4j.appender.A1=org.apache.log4j.ConsoleAppender
    #log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender
    log4j.appender.A1.File=logs/info.log
    log4j.appender.A1.Threshold=INFO
    log4j.appender.A1.layout=org.apache.log4j.PatternLayout
    #log4j.appender.A1.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} %t [%-5p]%c : %m%n
    log4j.appender.A1.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %l %m%n
    
    log4j.appender.A2=org.apache.log4j.ConsoleAppender
    #log4j.appender.A2=org.apache.log4j.DailyRollingFileAppender
    log4j.appender.A2.File=logs/error.log
    log4j.appender.A2.Threshold=ERROR
    log4j.appender.A2.layout=org.apache.log4j.PatternLayout
    #log4j.appender.A2.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} %t [%-5p]%c : %m%n
    log4j.appender.A2.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %l %m%n
    
    ### 把日志信息输出到控制台 ###
    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    #log4j.appender.stdout.Target=System.err
    log4j.appender.stdout.layout=org.apache.log4j.SimpleLayout
    ###显示SQL语句部分
    log4j.logger.com.ibatis=DEBUG
    
    #log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=DEBUG
    #log4j.logger.com.ibatis.common.jdbc.ScriptRunner=DEBUG
    #log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=DEBUG
    #log4j.logger.java.sql.Connection=DEBUG
    #log4j.logger.java.sql.Statement=DEBUG
    #log4j.logger.java.sql.PreparedStatement=DEBUG
    View Code

      <3.jdbc.properties

    driverClassName=com.mysql.jdbc.Driver
    jdbc.url=jdbc:mysql://127.0.0.1:3306/zb-project?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&autoReconnect=true&zeroDateTimeBehavior=convertToNull
    jdbc.username=root
    jdbc.password=root
    validationQuery=SELECT 1
    View Code

      <4.spring-mybatis.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:tx="http://www.springframework.org/schema/tx"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:context="http://www.springframework.org/schema/context"
           xsi:schemaLocation="http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/aop/spring-aop.xsd
            http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
            http://www.springframework.org/schema/tx
            http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context.xsd">
    
        <!--加载数据库配置-->
        <context:property-placeholder location="classpath:jdbc.properties" ignore-unresolvable="true"/>
        <!-- myBatis信息 -->
        <!-- 1.配置数据源 使用的是Druid数据源 -->
        <bean name="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
              init-method="init" destroy-method="close">
            <property name="url" value="${jdbc.url}" />
            <property name="username" value="${jdbc.username}" />
            <property name="password" value="${jdbc.password}" />
    
            <!-- 初始化连接大小 -->
            <property name="initialSize" value="0" />
            <!-- 连接池最大使用连接数量 -->
            <property name="maxActive" value="20" />
    
            <!-- 连接池最小空闲 -->
            <property name="minIdle" value="0" />
            <!-- 获取连接最大等待时间 -->
            <property name="maxWait" value="60000" />
            <property name="poolPreparedStatements" value="true" />
            <property name="maxPoolPreparedStatementPerConnectionSize"
                      value="33" />
            <!-- 用来检测有效sql -->
            <property name="validationQuery" value="${validationQuery}" />
            <property name="testOnBorrow" value="false" />
            <property name="testOnReturn" value="false" />
            <property name="testWhileIdle" value="true" />
            <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
            <property name="timeBetweenEvictionRunsMillis" value="60000" />
            <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
            <property name="minEvictableIdleTimeMillis" value="25200000" />
            <!-- 打开removeAbandoned功能 -->
            <property name="removeAbandoned" value="true" />
            <!-- 1800秒,也就是30分钟 -->
            <property name="removeAbandonedTimeout" value="1800" />
            <!-- 关闭abanded连接时输出错误日志 -->
            <property name="logAbandoned" value="true" />
            <!-- 监控数据库 -->
            <property name="filters" value="mergeStat" />
        </bean>
        <!--2.配置SqlSessionFactoryBean-->
        <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
            <property name="dataSource" ref="dataSource" />
            <property name="typeAliasesPackage" value="zb.mapper.entity"/>
            <property name="configLocation" value="classpath:sqlMapConfig.xml" />
            <!-- 自动扫描mapper.xml包 -->
            <property name="mapperLocations" value="classpath*:zb.mappers/*.xml" />
        </bean>
    
        <!-- 3.自动扫描dao(mapper)层包,该类会自动扫描sqlSessionFactory,不需配置 -->
        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
            <property name="basePackage" value="zb.mapper.api" />
            <!--这个属性,可有可无-->
            <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
        </bean>
    
    
        <!-- 4.进行事务配置 -->
        <!--4.1.配置事务管理器-->
        <bean id="transactionManager"
              class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource" ref="dataSource" />
        </bean>
    
        <!--方式一:注解式事务配置(当dubbo服务通过包扫描注册服务时,选用这种方式,且服务要改为接口实现形式)-->
        <!--<tx:annotation-driven transaction-manager="transactionManager"></tx:annotation-driven>-->
    
        <!--方式二:xml形式的事务配置-->
        <!-- 4.2.配置事务增强(指定增强方法名的匹配规则) -->
        <tx:advice id="transactionAdvice" transaction-manager="transactionManager">
            <tx:attributes>
                <tx:method name="insert*" propagation="REQUIRED" />
                <tx:method name="update*" propagation="REQUIRED" />
                <tx:method name="delete*" propagation="REQUIRED" />
                <tx:method name="save*" propagation="REQUIRED" />
                <tx:method name="get*" propagation="SUPPORTS" read-only="true" />
                <tx:method name="find*" propagation="SUPPORTS" read-only="true" />
                <tx:method name="select*" propagation="SUPPORTS" read-only="true" />
            </tx:attributes>
        </tx:advice>
        <!--⚫4.3.配置切入点和切面-->
        <aop:config>
            <!-- 切入点 -->
            <aop:pointcut expression="execution(* com.zbservice.LoginServiceImpl.*(..))" id="pointcut1"/>
            <!-- 切面,即表示把哪个增强用在哪个切入点上 -->
            <aop:advisor advice-ref="transactionAdvice" pointcut-ref="pointcut1"/>
        </aop:config>
    
    </beans>
    View Code

      <5.spring-aop.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:tx="http://www.springframework.org/schema/tx"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:context="http://www.springframework.org/schema/context"
           xsi:schemaLocation="http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/aop/spring-aop.xsd
            http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
            http://www.springframework.org/schema/tx
            http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context.xsd">
    
       <!--配置spring加强业务的信息(切面增强配置)-->
           <!--实例化增强类(advice)-->
        <bean id="zq" class="com.aopZengQiang.ZengQiang"></bean>
           <!-- 配置AOP的操作  -->
        <aop:config>
            <!-- 配置切入点,对LoginServiceImpl类里面的所有方法都增强 -->
            <aop:pointcut expression="execution(* com.zbservice.LoginServiceImpl.*(..))" id="pointcut1"></aop:pointcut>
            <!-- 配置切面,aop:aspect标签里面使用属性ref,ref属性值写增强类的bean的id值 -->
            <aop:aspect ref="zq">
                <!-- 增强类型 method属性:增强类的方法名称,pointcut-ref属性:切入点的id值-->
                <!-- 前置通知 -->
                <aop:before method="zqMethod1" pointcut-ref="pointcut1"></aop:before>
                <!-- 后置通知 -->
                <!--<aop:after-returning method="zqMethod2" pointcut-ref="pointcut1"></aop:after-returning>-->
                <!-- 环绕通知 -->
                <!--<aop:around method="zqMethod3" pointcut-ref="pointcut1"></aop:around>-->
            </aop:aspect>
        </aop:config>
    </beans>
    View Code

      <6.spring-registry.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"
           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://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-3.2.xsd">
    
        <!--dubbo配置-->
        <dubbo:application name="zb-server01"   version="1.0"/>
        <dubbo:registry protocol="zookeeper" address="zookeeper://114.55.95.79:2181?backup=114.55.31.202:2181,116.62.28.7:2181" />
        <dubbo:protocol name="dubbo" port="20883"/>
        <dubbo:provider timeout="100000" />
        <!--注册发布服务-->
        <!--方式一:包扫描-->
        <!--注解方式扫描注有com.alibaba.dubbo.config.annotation.Service的包,此种情况不能用xml事务配置-->
        <!--<dubbo:annotation package="com.zbservice"/>-->
    
        <!--方式二:注入bean-->
        <bean id="loginServiceImpl" class="com.zbservice.LoginServiceImpl"/>
        <dubbo:service interface="service.LoginService" ref="loginServiceImpl" protocol="dubbo" timeout="100000"/>
    
    </beans>
    View Code

      <7.spring-context.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:component-scan base-package="com.zbservice" />
        <import resource="classpath:spring/spring-mybatis.xml" />
        <import resource="classpath:spring/spring-registry.xml" />
        <import resource="classpath:spring/spring-application.xml" />
    </beans>
    View Code

      定义一个服务启动入口类

    package start;
    
    import org.springframework.context.ConfigurableApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    /**
     * Created by zb547 on 2018/5/14.
     */
    public class StartApplication {
        public static void main(String[] args) throws Exception {
            ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext("spring/spring-context.xml");
            System.out.println("server started...");
            while (true) {
                Thread.sleep(100);
            }
        }
    }
    View Code

    3.server-serviceImpl(存放服务接口实现)

    第四步:web项目创建

    1.web.xml配置信息(基本)

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app
            version="3.0"
            xmlns="http://java.sun.com/xml/ns/javaee"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
            http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    
        <display-name>zb-project</display-name>
    
        <welcome-file-list>
            <welcome-file>/WEB-INF/jsp/login.jsp</welcome-file>
        </welcome-file-list>
    
        <!--springMVC配置-->
        <!--前端控制器-->
        <servlet>
            <servlet-name>DispatcherServlet</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <init-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>classpath:/spring/spring-mvc.xml</param-value>
            </init-param>
            <load-on-startup>1</load-on-startup>
        </servlet>
    
        <servlet-mapping>
            <servlet-name>DispatcherServlet</servlet-name>
            <url-pattern>/</url-pattern>
        </servlet-mapping>
        <!--释放静态资源-->
        <servlet-mapping>
            <!-- 假如静态内容css和js放在 static 目录下,由容器定义的 default servlet 处理 -->
            <servlet-name>default</servlet-name>
            <url-pattern>/static/*</url-pattern>
        </servlet-mapping>
        <!--spring配置-->
        <!--spring监听器,优先级高于过滤器,配在哪都可以-->
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
    <!--    <listener>
            <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
        </listener>-->
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:/spring/spring-application.xml</param-value>
        </context-param>
    
        <!--过滤器设置编码-->
        <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>
            <init-param>
                <param-name>forceEncoding</param-name>
                <param-value>true</param-value>
            </init-param>
        </filter>
        <filter-mapping>
            <filter-name>encodingFilter</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
        <!--自定义过滤器进行登陆判断-->
    <!--    <filter>
            <filter-name>loginFilter</filter-name>
            <filter-class>zb.filter.LoginFilter</filter-class>
        </filter>
        <filter-mapping>
            <filter-name>loginFilter</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>-->
    </web-app>
    View Code

    2.spring-mvc.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!--suppress ALL -->
    <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"
           xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xsi:schemaLocation="http://www.springframework.org/schema/aop
          http://www.springframework.org/schema/aop/spring-aop.xsd
          http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
          http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context-3.2.xsd
          http://www.springframework.org/schema/mvc
          http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
          http://code.alibabatech.com/schema/dubbo
          http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
        <!--
               自动扫描controller包下的所有类,如果@Controller注入为bean
               并将bean依赖注入,即dubbo服务端暴露的Service注入到Controller中,
               加上dubbo标签可以用@Reference
           -->
        <dubbo:annotation package="zb.controller"/>
        <context:component-scan base-package="zb.controller" />
        
        <!--springmvc注解驱动-->
        <mvc:annotation-driven>
            <mvc:message-converters register-defaults="true">
                <!-- 消息转换器,当springMVC返回字符串时,进行字符串编码设置 -->
                <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                    <property name="supportedMediaTypes">
                        <list>
                            <value>text/html; charset=UTF-8</value>
                            <value>application/json;charset=UTF-8</value>
                        </list>
                    </property>
                </bean>
                <!-- 消息转换器,当springMVC接收和返回json数据格式调用的转换器,进行字符串编码设置 -->
                <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
                    <property name="supportedMediaTypes">
                        <list>
                            <value>text/html; charset=UTF-8</value>
                            <value>application/json;charset=UTF-8</value>
                        </list>
                    </property>
                </bean>
            </mvc:message-converters>
        </mvc:annotation-driven>
    
        <!--视图解析器配在-->
        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/WEB-INF/jsp/"/>
            <property name="suffix" value=".jsp"/>
        </bean>
    
        <!--上传文件用的-->
        <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
            <property name="maxUploadSize">
                <value>2048000000</value>
            </property>
            <property name="maxInMemorySize">
                <value>2048000</value>
            </property>
            <property name="defaultEncoding">
                <value>UTF-8</value>
            </property>
        </bean>
    </beans>
    View Code

    3.spring-application.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!--suppress ALL -->
    <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"
           xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xsi:schemaLocation="http://www.springframework.org/schema/aop
          http://www.springframework.org/schema/aop/spring-aop.xsd
          http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
          http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context-3.2.xsd
          http://www.springframework.org/schema/mvc
          http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
          http://code.alibabatech.com/schema/dubbo
          http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
    
        <context:component-scan base-package="zb.controller" />
    
        <!-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 -->
        <dubbo:application name="zb-web"/>
        <!-- 使用zookeeper广播注册中心暴露服务地址 -->
        <dubbo:registry address="zookeeper://114.55.95.79:2181?backup=114.55.31.202:2181,116.62.28.7:2181"/>
    </beans>
    View Code

    ps:基本信息这样,后期有待完善

        web端可以完全用dubbo扫描形式(扫描dubbo的@Reference注解)进行服务获取,如果服务端serviceImpl很多的话,也可以进行包扫描(dubbo的@Service)的形式

    进行服务发布,但是对于需要添加事务的serviceImpl,需要进行(spring的@Service)的注解,然后spring.xml文件中dubbo的接口实现方式进行服务发布,然后进行注解形式的事务控制。

            

  • 相关阅读:
    jmeter教程索引
    JMeter 中_time 函数的使用(时间戳、当前时间)
    通用分页存储过程
    如何才算掌握Java(J2SE篇) 转载
    Java 外企面试若干题
    Java 有用的网址 转载
    JDBC链接基本步骤
    java基础学习 视频学习 数据类型以及运算符
    Java基础 构造对象初始化变量的顺序浅见
    全面解析《嵌入式程序员应该知道的16个问题》 转载
  • 原文地址:https://www.cnblogs.com/zbdouble/p/9045886.html
Copyright © 2020-2023  润新知