ssm+maven+dubbo项目搭建

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

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

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




         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    
        zb-Project
        zb-dubboDemo
        1.0-SNAPSHOT
    
    4.0.0

    zb-common

    zb-common
    jar
    http://maven.apache.org

    
        UTF-8
        1.7
        1.7
    

    
        
            junit
            junit
            3.8.1
            test
        


        
            commons-cli
            commons-cli
            1.2
        
        
            commons-io
            commons-io
            2.3
        
        
            org.openoffice
            juh
            3.0.1
        
        
            org.openoffice
            jurt
            3.0.1
        
        
            org.openoffice
            ridl
            3.0.1
        
        
        
        
        
        
        
            org.openoffice
            unoil
            3.0.1
        
        
            com.thoughtworks.xstream
            xstream
            1.3.1
        
        
            com.artofsolving
            jodconverter
            2.2.1
            
                
                    slf4j-api
                    org.slf4j
                
            
        

    

    
        
            
                
                    maven-clean-plugin
                    3.0.0
                
                
                
                    maven-resources-plugin
                    3.0.2
                
                
                    maven-compiler-plugin
                    3.7.0
                
                
                    maven-surefire-plugin
                    2.20.1
                
                
                    maven-jar-plugin
                    3.0.2
                
                
                    maven-install-plugin
                    2.5.2
                
                
                    maven-deploy-plugin
                    2.8.2
                
            
        
    
View Code

第三布:server子项目配置

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

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

    <1.sqlMapConfig.xml




    
        
        
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
        
    
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



       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">

    
    
    
    
    class="com.alibaba.druid.pool.DruidDataSource"
          init-method="init" destroy-method="close">
        
        
        

        
        
        
        

        
        
        
        
        
        
                  value="33" />
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
    
    
    class="org.mybatis.spring.SqlSessionFactoryBean">
        
        
        
        
        
    

    
    class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        
        
        
    


    
    
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        
    

    
    

    
    
    
        
            
            
            
            
            
            
            
        
    
    
    
        
        
        
        
    

View Code

  <5.spring-aop.xml



       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">

   
       
    class="com.aopZengQiang.ZengQiang">
       
    
        
        
        
        
            
            
            
            
            
            
            
        
    
View Code

  <6.spring-registry.xml



       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">

    
    
    
    
    
    
    
    
    

    
    class="com.zbservice.LoginServiceImpl"/>
    interface="service.LoginService" ref="loginServiceImpl" protocol="dubbo" timeout="100000"/>

View Code

  <7.spring-context.xml



       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">

    package="com.zbservice" />
    <import resource="classpath:spring/spring-mybatis.xml" />
    <import resource="classpath:spring/spring-registry.xml" />
    <import resource="classpath:spring/spring-application.xml" />
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配置信息(基本)


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">

    zb-project

    
        /WEB-INF/jsp/login.jsp
    

    
    
    
        DispatcherServlet
        class>org.springframework.web.servlet.DispatcherServletclass>
        
            contextConfigLocation
            classpath:/spring/spring-mvc.xml
        
        1
    

    
        DispatcherServlet
        /
    
    
    
        
        default
        /static/*
    
    
    
    
        org.springframework.web.context.ContextLoaderListener
    

    
        contextConfigLocation
        classpath:/spring/spring-application.xml
    

    
    
        encodingFilter
        org.springframework.web.filter.CharacterEncodingFilter
        
            encoding
            UTF-8
        
        
            forceEncoding
            true
        
    
    
        encodingFilter
        /*
    
    

View Code

2.spring-mvc.xml




       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">
    
    package="zb.controller"/>
    package="zb.controller" />
    
    
    
        
            
            class="org.springframework.http.converter.StringHttpMessageConverter">
                
                    
                        text/html; charset=UTF-8
                        application/json;charset=UTF-8
                    
                
            
            
            class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
                
                    
                        text/html; charset=UTF-8
                        application/json;charset=UTF-8
                    
                
            
        
    

    
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        
        
    

    
    class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        
            2048000000
        
        
            2048000
        
        
            UTF-8
        
    
View Code

3.spring-application.xml




       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">

    package="zb.controller" />

    
    
    
    
View Code

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

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

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

        

转载于:https://www.cnblogs.com/zbdouble/p/9045886.html

你可能感兴趣的:(java,json,测试)