zoukankan      html  css  js  c++  java
  • springboot的maven多模块项目架构微服务搭建——依赖方式的多模块演化为微服务项目

    在上一篇依赖方式多模块的基础上对项目进行改造。主要改造user-service项目,service要配置mapper。mybatis及数据库相关的东西,后面的接口消费方user就不再需要了

    注意:以下代码是在不同场所的机器上写的,数据库什么的会有不同,结构也会有不同,最终的代码会以其中一个传递到本人git上,这里记录的是本人总结的一些思路什么的,稍微修改配置,配置一致,就可以运行的

    代码如下:

    pom

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     3     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     4     <modelVersion>4.0.0</modelVersion>
     5 
     6     <parent>
     7     <groupId>com.sharp</groupId>
     8     <artifactId>sharp-pom</artifactId>
     9     <version>0.0.1-SNAPSHOT</version>
    10     </parent>
    11     <artifactId>sharp-user-service</artifactId>
    12     <packaging>jar</packaging>
    13 
    14     <name>sharp-user-service</name>
    15     <description>Forward project for Spring Boot</description>
    16     <dependencies>
    17         <dependency>
    18             <groupId>com.sharp</groupId>
    19             <artifactId>sharp-common</artifactId>
    20             <version>${project.parent.version}</version>
    21         </dependency>
    22         <dependency>
    23             <groupId>com.sharp</groupId>
    24             <artifactId>sharp-entity</artifactId>
    25             <version>${project.parent.version}</version>
    26         </dependency>
    27         <dependency>
    28             <groupId>com.sharp</groupId>
    29             <artifactId>sharp-mapper</artifactId>
    30             <version>${project.parent.version}</version>
    31         </dependency>
    32         <dependency>
    33         <groupId>com.sharp</groupId>
    34         <artifactId>sharp-user-service-api</artifactId>
    35         <version>${project.parent.version}</version>
    36         </dependency>
    37         <dependency>
    38             <groupId>org.mybatis.spring.boot</groupId>
    39             <artifactId>mybatis-spring-boot-starter</artifactId>
    40         </dependency>    
    41         <dependency>
    42             <groupId>org.apache.zookeeper</groupId>
    43             <artifactId>zookeeper</artifactId>
    44         </dependency>
    45         <!-- https://mvnrepository.com/artifact/com.alibaba/dubbo -->
    46         <dependency>
    47             <groupId>com.alibaba</groupId>
    48             <artifactId>dubbo</artifactId>
    49             <version>2.6.2</version>
    50         </dependency>
    51         <dependency>
    52                 <groupId>org.springframework</groupId>
    53                 <artifactId>spring-jdbc</artifactId>
    54             </dependency>
    55         <dependency>
    56             <groupId>mysql</groupId>
    57             <artifactId>mysql-connector-java</artifactId>
    58             <scope>runtime</scope>
    59         </dependency>
    60         <dependency>
    61         <groupId>org.apache.curator</groupId>
    62         <artifactId>curator-framework</artifactId>
    63         <version>2.8.0</version>
    64     </dependency>
    65     <dependency>
    66         <groupId>org.apache.curator</groupId>
    67         <artifactId>curator-recipes</artifactId>
    68         <version>2.8.0</version>
    69     </dependency>
    70 
    71 </dependencies>
    72 
    73     <build>
    74         <plugins>
    75             <plugin>
    76                 <groupId>org.springframework.boot</groupId>
    77                 <artifactId>spring-boot-maven-plugin</artifactId>
    78             </plugin>
    79 <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-plugin -->
    80 <plugin>
    81     <groupId>org.apache.maven.plugins</groupId>
    82     <artifactId>maven-surefire-plugin</artifactId>
    83     <version>2.21.0</version>
    84     <configuration>
    85         <skipTests>true</skipTests>
    86     </configuration>
    87 </plugin>
    88 </plugins>
    89         
    90     </build>
    91 
    92 
    93 </project>

    yml文件

    spring:
      profiles:
        active:
        - local
      datasource:
        driver-class-name: com.mysql.jdbc.Driver
        url: jdbc:mysql://127.0.0.1:3306/dealer?serverTimezone=GMT%2B8
        username: root
        password: 123456
    mybatis:
      config-location: classpath:mybatis/mybatis-config.xml
      mapper-locations: classpath:mybatis/mapper/*.xml
      type-aliases-package: com.sharp.forward.entity

    local

    server:
      port: 8886
    zookeeper.address: 192.168.1.105:2181

    dubbo

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
           xmlns="http://www.springframework.org/schema/beans"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
           http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
    
        <!-- consumer's application name, used for tracing dependency relationship (not a matching criterion),
        don't set it same as provider -->
        <dubbo:application name="userService"/>
        <!-- use multicast registry center to discover service -->
        <dubbo:registry protocol="zookeeper" address="zookeeper://192.168.1.105:2181"/>
        <!-- use dubbo protocol to export service on port 20880 -->
        <dubbo:protocol name="dubbo" port="20880"/>
        <!-- service implementation, as same as regular local bean -->
        <bean id="userService" class="com.sharp.forward.user.service.impl.UserServiceImpl"/>
        <!-- declare the service interface to be exported -->
        <dubbo:service interface="com.sharp.forward.user.service.UserService" ref="userService"/>
    </beans>

    项目启动类

    package com.sharp.forward;
    
    import org.mybatis.spring.annotation.MapperScan;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.context.annotation.ImportResource;
    
    @SpringBootApplication
    @ImportResource("config/application-dubbo.xml")
    @MapperScan("com.sharp.forward.mapper")
    public class UserServiceApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(UserServiceApplication.class, args);
        }
    }

    结构

    运行后

      1 SLF4J: Class path contains multiple SLF4J bindings.
      2 SLF4J: Found binding in [jar:file:/D:/javaEnvironment/repo/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
      3 SLF4J: Found binding in [jar:file:/D:/javaEnvironment/repo/org/slf4j/slf4j-log4j12/1.7.25/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
      4 SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
      5 SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
      6 
      7   .   ____          _            __ _ _
      8  /\ / ___'_ __ _ _(_)_ __  __ _    
      9 ( ( )\___ | '_ | '_| | '_ / _` |    
     10  \/  ___)| |_)| | | | | || (_| |  ) ) ) )
     11   '  |____| .__|_| |_|_| |_\__, | / / / /
     12  =========|_|==============|___/=/_/_/_/
     13  :: Spring Boot ::        (v2.0.6.RELEASE)
     14 
     15 2018-12-02 20:13:12.238  INFO 32764 --- [           main] c.sharp.forward.UserServiceApplication   : Starting UserServiceApplication on litan with PID 32764 (D:worksheetsharp-user-service	argetclasses started by litan in D:worksheetsharp-user-service)
     16 2018-12-02 20:13:12.241  INFO 32764 --- [           main] c.sharp.forward.UserServiceApplication   : The following profiles are active: local
     17 2018-12-02 20:13:12.353  INFO 32764 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@49139829: startup date [Sun Dec 02 20:13:12 CST 2018]; root of context hierarchy
     18 2018-12-02 20:13:13.301  INFO 32764 --- [           main] o.s.b.f.xml.XmlBeanDefinitionReader      : Loading XML bean definitions from class path resource [config/application-dubbo.xml]
     19 log4j:WARN No appenders could be found for logger (com.alibaba.dubbo.common.logger.LoggerFactory).
     20 log4j:WARN Please initialize the log4j system properly.
     21 log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
     22 2018-12-02 20:13:13.545  INFO 32764 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'userService' with a different definition: replacing [Generic bean: class [com.sharp.forward.user.service.impl.UserServiceImpl]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [D:worksheetsharp-user-service	argetclassescomsharpforwarduserserviceimplUserServiceImpl.class]] with [Generic bean: class [com.sharp.forward.user.service.impl.UserServiceImpl]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in class path resource [config/application-dubbo.xml]]
     23 2018-12-02 20:13:15.970  INFO 32764 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8886 (http)
     24 2018-12-02 20:13:16.059  INFO 32764 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
     25 2018-12-02 20:13:16.059  INFO 32764 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.34
     26 2018-12-02 20:13:16.077  INFO 32764 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [D:javajava1.8jre1.8in;C:WINDOWSSunJavain;C:WINDOWSsystem32;C:WINDOWS;C:ProgramDataOracleJavajavapath;D:javaoracleproduct11.2.0dbhome_1in;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;C:WINDOWSSystem32WindowsPowerShellv1.0;C:Program Files (x86)Common Fileslenovoeasyplussdkin;C:Program Files (x86)ATI TechnologiesATI.ACECore-Static;C:Program Files (x86)MySQLMySQL Fabric 1.5.2 & MySQL Utilities 1.5.2 1.5;C:Program Files (x86)MySQLMySQL Fabric 1.5.2 & MySQL Utilities 1.5.2 1.5Doctrine extensions for PHP;D:javajava1.8jdk1.8in;JAVA_HOME%jrein;D:java_reviewapache-tomcat-7.0.67in;D:我的软件;办公软;svnServerin;%ma;en_home%in;D:我的软件数据库putty;C:Pro;ram FilesIntelWiFiin;C:Program FilesCommon FilesIntelWirelessCommon;";D:我的软件专业软件zookeeperzookeeper-3.4.9/bin; D:我的软件专业软件zookeeperzookeeper-3.4.9/conf";D:javajava1.8jdk1.8in;C:Program FilesTortoiseGitin;C:Program FilesGitcmd;C:WINDOWSSystem32OpenSSH;D:java软件安装资源汇总maven建项目apache-maven-3.3.9-binapache-maven-3.3.9in;D:protobufcin;C:UserslitanAppDataLocalMicrosoftWindowsApps;D:java软件安装资源汇总2017-6-25apache-maven-3.3.9-binapache-maven-3.3.9in;;.]
     27 2018-12-02 20:13:16.372  INFO 32764 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
     28 2018-12-02 20:13:16.373  INFO 32764 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 4024 ms
     29 2018-12-02 20:13:16.532  INFO 32764 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
     30 2018-12-02 20:13:16.634  INFO 32764 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
     31 2018-12-02 20:13:16.635  INFO 32764 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
     32 2018-12-02 20:13:16.635  INFO 32764 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
     33 2018-12-02 20:13:16.635  INFO 32764 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
     34 Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
     35 2018-12-02 20:13:18.268  INFO 32764 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
     36 2018-12-02 20:13:18.731  INFO 32764 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@49139829: startup date [Sun Dec 02 20:13:12 CST 2018]; root of context hierarchy
     37 2018-12-02 20:13:18.889  INFO 32764 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
     38 2018-12-02 20:13:18.893  INFO 32764 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
     39 2018-12-02 20:13:18.959  INFO 32764 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
     40 2018-12-02 20:13:18.959  INFO 32764 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
     41 2018-12-02 20:13:19.490  INFO 32764 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
     42 2018-12-02 20:13:19.492  INFO 32764 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'dataSource' has been autodetected for JMX exposure
     43 2018-12-02 20:13:19.502  INFO 32764 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
     44 2018-12-02 20:13:20.860  INFO 32764 --- [           main] o.a.c.f.imps.CuratorFrameworkImpl        : Starting
     45 2018-12-02 20:13:20.875  INFO 32764 --- [           main] org.apache.zookeeper.ZooKeeper           : Client environment:zookeeper.version=3.4.13-2d71af4dbe22557fda74f9a9b4309b15a7487f03, built on 06/29/2018 00:39 GMT
     46 2018-12-02 20:13:20.875  INFO 32764 --- [           main] org.apache.zookeeper.ZooKeeper           : Client environment:host.name=windows10.microdone.cn
     47 2018-12-02 20:13:20.875  INFO 32764 --- [           main] org.apache.zookeeper.ZooKeeper           : Client environment:java.version=1.8.0_161
     48 2018-12-02 20:13:20.875  INFO 32764 --- [           main] org.apache.zookeeper.ZooKeeper           : Client environment:java.vendor=Oracle Corporation
     49 2018-12-02 20:13:20.875  INFO 32764 --- [           main] org.apache.zookeeper.ZooKeeper           : Client environment:java.home=D:javajava1.8jre1.8
     50 2018-12-02 20:13:20.875  INFO 32764 --- [           main] org.apache.zookeeper.ZooKeeper           : Client environment:java.class.path=D:javajava1.8jre1.8lib
    esources.jar;D:javajava1.8jre1.8lib
    t.jar;D:javajava1.8jre1.8libjsse.jar;D:javajava1.8jre1.8libjce.jar;D:javajava1.8jre1.8libcharsets.jar;D:javajava1.8jre1.8libjfr.jar;D:javajava1.8jre1.8libextaccess-bridge-64.jar;D:javajava1.8jre1.8libextcldrdata.jar;D:javajava1.8jre1.8libextdnsns.jar;D:javajava1.8jre1.8libextjaccess.jar;D:javajava1.8jre1.8libextjfxrt.jar;D:javajava1.8jre1.8libextlocaledata.jar;D:javajava1.8jre1.8libext
    ashorn.jar;D:javajava1.8jre1.8libextsunec.jar;D:javajava1.8jre1.8libextsunjce_provider.jar;D:javajava1.8jre1.8libextsunmscapi.jar;D:javajava1.8jre1.8libextsunpkcs11.jar;D:javajava1.8jre1.8libextzipfs.jar;D:worksheetsharp-user-service	argetclasses;D:worksheetsharp-common	argetclasses;D:javaEnvironment
    epoorgspringframeworkootspring-boot-starter-web2.0.6.RELEASEspring-boot-starter-web-2.0.6.RELEASE.jar;D:javaEnvironment
    epoorgspringframeworkootspring-boot-starter-json2.0.6.RELEASEspring-boot-starter-json-2.0.6.RELEASE.jar;D:javaEnvironment
    epocomfasterxmljacksoncorejackson-databind2.9.7jackson-databind-2.9.7.jar;D:javaEnvironment
    epocomfasterxmljacksoncorejackson-annotations2.9.0jackson-annotations-2.9.0.jar;D:javaEnvironment
    epocomfasterxmljacksoncorejackson-core2.9.7jackson-core-2.9.7.jar;D:javaEnvironment
    epocomfasterxmljacksondatatypejackson-datatype-jdk82.9.7jackson-datatype-jdk8-2.9.7.jar;D:javaEnvironment
    epocomfasterxmljacksondatatypejackson-datatype-jsr3102.9.7jackson-datatype-jsr310-2.9.7.jar;D:javaEnvironment
    epocomfasterxmljacksonmodulejackson-module-parameter-names2.9.7jackson-module-parameter-names-2.9.7.jar;D:javaEnvironment
    epoorgspringframeworkootspring-boot-starter-tomcat2.0.6.RELEASEspring-boot-starter-tomcat-2.0.6.RELEASE.jar;D:javaEnvironment
    epoorgapache	omcatembed	omcat-embed-core8.5.34	omcat-embed-core-8.5.34.jar;D:javaEnvironment
    epoorgapache	omcatembed	omcat-embed-el8.5.34	omcat-embed-el-8.5.34.jar;D:javaEnvironment
    epoorgapache	omcatembed	omcat-embed-websocket8.5.34	omcat-embed-websocket-8.5.34.jar;D:javaEnvironment
    epoorghibernatevalidatorhibernate-validator6.0.13.Finalhibernate-validator-6.0.13.Final.jar;D:javaEnvironment
    epojavaxvalidationvalidation-api2.0.1.Finalvalidation-api-2.0.1.Final.jar;D:javaEnvironment
    epoorgjbossloggingjboss-logging3.3.2.Finaljboss-logging-3.3.2.Final.jar;D:javaEnvironment
    epocomfasterxmlclassmate1.3.4classmate-1.3.4.jar;D:javaEnvironment
    epoorgspringframeworkspring-web5.0.10.RELEASEspring-web-5.0.10.RELEASE.jar;D:javaEnvironment
    epoorgspringframeworkspring-webmvc5.0.10.RELEASEspring-webmvc-5.0.10.RELEASE.jar;D:javaEnvironment
    epoorgspringframeworkootspring-boot-starter-test2.0.6.RELEASEspring-boot-starter-test-2.0.6.RELEASE.jar;D:javaEnvironment
    epoorgspringframeworkootspring-boot-test2.0.6.RELEASEspring-boot-test-2.0.6.RELEASE.jar;D:javaEnvironment
    epoorgspringframeworkootspring-boot-test-autoconfigure2.0.6.RELEASEspring-boot-test-autoconfigure-2.0.6.RELEASE.jar;D:javaEnvironment
    epocomjaywayjsonpathjson-path2.4.0json-path-2.4.0.jar;D:javaEnvironment
    epo
    etminidevjson-smart2.3json-smart-2.3.jar;D:javaEnvironment
    epo
    etminidevaccessors-smart1.2accessors-smart-1.2.jar;D:javaEnvironment
    epoorgow2asmasm5.0.4asm-5.0.4.jar;D:javaEnvironment
    epojunitjunit4.12junit-4.12.jar;D:javaEnvironment
    epoorgassertjassertj-core3.9.1assertj-core-3.9.1.jar;D:javaEnvironment
    epoorgmockitomockito-core2.15.0mockito-core-2.15.0.jar;D:javaEnvironment
    epo
    etytebuddyyte-buddy1.7.11yte-buddy-1.7.11.jar;D:javaEnvironment
    epo
    etytebuddyyte-buddy-agent1.7.11yte-buddy-agent-1.7.11.jar;D:javaEnvironment
    epoorgobjenesisobjenesis2.6objenesis-2.6.jar;D:javaEnvironment
    epoorghamcresthamcrest-core1.3hamcrest-core-1.3.jar;D:javaEnvironment
    epoorghamcresthamcrest-library1.3hamcrest-library-1.3.jar;D:javaEnvironment
    epoorgskyscreamerjsonassert1.5.0jsonassert-1.5.0.jar;D:javaEnvironment
    epocomvaadinexternalgoogleandroid-json.0.20131108.vaadin1android-json-0.0.20131108.vaadin1.jar;D:javaEnvironment
    epoorgspringframeworkspring-test5.0.10.RELEASEspring-test-5.0.10.RELEASE.jar;D:javaEnvironment
    epoorgxmlunitxmlunit-core2.5.1xmlunit-core-2.5.1.jar;D:worksheetsharp-entity	argetclasses;D:javaEnvironment
    epoorgspringframeworkootspring-boot-starter2.0.6.RELEASEspring-boot-starter-2.0.6.RELEASE.jar;D:javaEnvironment
    epoorgspringframeworkootspring-boot2.0.6.RELEASEspring-boot-2.0.6.RELEASE.jar;D:javaEnvironment
    epoorgspringframeworkootspring-boot-autoconfigure2.0.6.RELEASEspring-boot-autoconfigure-2.0.6.RELEASE.jar;D:javaEnvironment
    epoorgspringframeworkootspring-boot-starter-logging2.0.6.RELEASEspring-boot-starter-logging-2.0.6.RELEASE.jar;D:javaEnvironment
    epochqoslogbacklogback-classic1.2.3logback-classic-1.2.3.jar;D:javaEnvironment
    epochqoslogbacklogback-core1.2.3logback-core-1.2.3.jar;D:javaEnvironment
    epoorgapachelogginglog4jlog4j-to-slf4j2.10.0log4j-to-slf4j-2.10.0.jar;D:javaEnvironment
    epoorgapachelogginglog4jlog4j-api2.10.0log4j-api-2.10.0.jar;D:javaEnvironment
    epoorgslf4jjul-to-slf4j1.7.25jul-to-slf4j-1.7.25.jar;D:javaEnvironment
    epojavaxannotationjavax.annotation-api1.3.2javax.annotation-api-1.3.2.jar;D:javaEnvironment
    epoorgyamlsnakeyaml1.19snakeyaml-1.19.jar;D:worksheetsharp-mapper	argetclasses;D:javaEnvironment
    epoorgmybatismybatis3.4.6mybatis-3.4.6.jar;D:javaEnvironment
    epoorgmybatismybatis-spring1.3.2mybatis-spring-1.3.2.jar;D:worksheetsharp-user-service-api	argetclasses;D:javaEnvironment
    epoorgmybatisspringootmybatis-spring-boot-starter1.3.2mybatis-spring-boot-starter-1.3.2.jar;D:javaEnvironment
    epoorgspringframeworkootspring-boot-starter-jdbc2.0.6.RELEASEspring-boot-starter-jdbc-2.0.6.RELEASE.jar;D:javaEnvironment
    epocomzaxxerHikariCP2.7.9HikariCP-2.7.9.jar;D:javaEnvironment
    epoorgmybatisspringootmybatis-spring-boot-autoconfigure1.3.2mybatis-spring-boot-autoconfigure-1.3.2.jar;D:javaEnvironment
    epoorgapachezookeeperzookeeper3.4.13zookeeper-3.4.13.jar;D:javaEnvironment
    epoorgslf4jslf4j-api1.7.25slf4j-api-1.7.25.jar;D:javaEnvironment
    epoorgslf4jslf4j-log4j121.7.25slf4j-log4j12-1.7.25.jar;D:javaEnvironment
    epolog4jlog4j1.2.17log4j-1.2.17.jar;D:javaEnvironment
    epojlinejline.9.94jline-0.9.94.jar;D:javaEnvironment
    epoorgapacheyetusaudience-annotations.5.0audience-annotations-0.5.0.jar;D:javaEnvironment
    epoio
    etty
    etty3.10.6.Final
    etty-3.10.6.Final.jar;D:javaEnvironment
    epocomalibabadubbo2.6.2dubbo-2.6.2.jar;D:javaEnvironment
    epoorgspringframeworkspring-context5.0.10.RELEASEspring-context-5.0.10.RELEASE.jar;D:javaEnvironment
    epoorgspringframeworkspring-aop5.0.10.RELEASEspring-aop-5.0.10.RELEASE.jar;D:javaEnvironment
    epoorgspringframeworkspring-expression5.0.10.RELEASEspring-expression-5.0.10.RELEASE.jar;D:javaEnvironment
    epoorgjavassistjavassist3.20.0-GAjavassist-3.20.0-GA.jar;D:javaEnvironment
    epoorgjboss
    etty
    etty3.2.5.Final
    etty-3.2.5.Final.jar;D:javaEnvironment
    epoorgspringframeworkspring-jdbc5.1.1.RELEASEspring-jdbc-5.1.1.RELEASE.jar;D:javaEnvironment
    epoorgspringframeworkspring-beans5.0.10.RELEASEspring-beans-5.0.10.RELEASE.jar;D:javaEnvironment
    epoorgspringframeworkspring-core5.0.10.RELEASEspring-core-5.0.10.RELEASE.jar;D:javaEnvironment
    epoorgspringframeworkspring-jcl5.0.10.RELEASEspring-jcl-5.0.10.RELEASE.jar;D:javaEnvironment
    epoorgspringframeworkspring-tx5.0.10.RELEASEspring-tx-5.0.10.RELEASE.jar;D:javaEnvironment
    epomysqlmysql-connector-java8.0.12mysql-connector-java-8.0.12.jar;D:javaEnvironment
    epocomgoogleprotobufprotobuf-java2.6.0protobuf-java-2.6.0.jar;D:javaEnvironment
    epoorgapachecuratorcurator-framework2.8.0curator-framework-2.8.0.jar;D:javaEnvironment
    epoorgapachecuratorcurator-client2.8.0curator-client-2.8.0.jar;D:javaEnvironment
    epocomgoogleguavaguava16.0.1guava-16.0.1.jar;D:javaEnvironment
    epoorgapachecuratorcurator-recipes2.8.0curator-recipes-2.8.0.jar
     51 2018-12-02 20:13:20.875  INFO 32764 --- [           main] org.apache.zookeeper.ZooKeeper           : Client environment:java.library.path=D:javajava1.8jre1.8in;C:WINDOWSSunJavain;C:WINDOWSsystem32;C:WINDOWS;C:ProgramDataOracleJavajavapath;D:javaoracleproduct11.2.0dbhome_1in;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;C:WINDOWSSystem32WindowsPowerShellv1.0;C:Program Files (x86)Common Fileslenovoeasyplussdkin;C:Program Files (x86)ATI TechnologiesATI.ACECore-Static;C:Program Files (x86)MySQLMySQL Fabric 1.5.2 & MySQL Utilities 1.5.2 1.5;C:Program Files (x86)MySQLMySQL Fabric 1.5.2 & MySQL Utilities 1.5.2 1.5Doctrine extensions for PHP;D:javajava1.8jdk1.8in;JAVA_HOME%jrein;D:java_reviewapache-tomcat-7.0.67in;D:我的软件;办公软;svnServerin;%ma;en_home%in;D:我的软件数据库putty;C:Pro;ram FilesIntelWiFiin;C:Program FilesCommon FilesIntelWirelessCommon;";D:我的软件专业软件zookeeperzookeeper-3.4.9/bin; D:我的软件专业软件zookeeperzookeeper-3.4.9/conf";D:javajava1.8jdk1.8in;C:Program FilesTortoiseGitin;C:Program FilesGitcmd;C:WINDOWSSystem32OpenSSH;D:java软件安装资源汇总maven建项目apache-maven-3.3.9-binapache-maven-3.3.9in;D:protobufcin;C:UserslitanAppDataLocalMicrosoftWindowsApps;D:java软件安装资源汇总2017-6-25apache-maven-3.3.9-binapache-maven-3.3.9in;;.
     52 2018-12-02 20:13:20.875  INFO 32764 --- [           main] org.apache.zookeeper.ZooKeeper           : Client environment:java.io.tmpdir=C:UserslitanAppDataLocalTemp
     53 2018-12-02 20:13:20.876  INFO 32764 --- [           main] org.apache.zookeeper.ZooKeeper           : Client environment:java.compiler=<NA>
     54 2018-12-02 20:13:20.876  INFO 32764 --- [           main] org.apache.zookeeper.ZooKeeper           : Client environment:os.name=Windows 10
     55 2018-12-02 20:13:20.876  INFO 32764 --- [           main] org.apache.zookeeper.ZooKeeper           : Client environment:os.arch=amd64
     56 2018-12-02 20:13:20.876  INFO 32764 --- [           main] org.apache.zookeeper.ZooKeeper           : Client environment:os.version=10.0
     57 2018-12-02 20:13:20.876  INFO 32764 --- [           main] org.apache.zookeeper.ZooKeeper           : Client environment:user.name=litan
     58 2018-12-02 20:13:20.876  INFO 32764 --- [           main] org.apache.zookeeper.ZooKeeper           : Client environment:user.home=C:Userslitan
     59 2018-12-02 20:13:20.876  INFO 32764 --- [           main] org.apache.zookeeper.ZooKeeper           : Client environment:user.dir=D:worksheetsharp-user-service
     60 2018-12-02 20:13:20.877  INFO 32764 --- [           main] org.apache.zookeeper.ZooKeeper           : Initiating client connection, connectString=192.168.1.105:2181 sessionTimeout=60000 watcher=org.apache.curator.ConnectionState@56a4f272
     61 2018-12-02 20:13:26.570 ERROR 32764 --- [           main] org.apache.curator.ConnectionState       : Connection timed out for connection string (192.168.1.105:2181) and timeout (5000) / elapsed (5696)
     62 
     63 org.apache.curator.CuratorConnectionLossException: KeeperErrorCode = ConnectionLoss
     64     at org.apache.curator.ConnectionState.checkTimeouts(ConnectionState.java:197) [curator-client-2.8.0.jar:na]
     65     at org.apache.curator.ConnectionState.getZooKeeper(ConnectionState.java:87) [curator-client-2.8.0.jar:na]
     66     at org.apache.curator.CuratorZookeeperClient.getZooKeeper(CuratorZookeeperClient.java:115) [curator-client-2.8.0.jar:na]
     67     at org.apache.curator.framework.imps.CuratorFrameworkImpl.getZooKeeper(CuratorFrameworkImpl.java:477) [curator-framework-2.8.0.jar:na]
     68     at org.apache.curator.framework.imps.ExistsBuilderImpl$2.call(ExistsBuilderImpl.java:172) [curator-framework-2.8.0.jar:na]
     69     at org.apache.curator.framework.imps.ExistsBuilderImpl$2.call(ExistsBuilderImpl.java:161) [curator-framework-2.8.0.jar:na]
     70     at org.apache.curator.RetryLoop.callWithRetry(RetryLoop.java:107) [curator-client-2.8.0.jar:na]
     71     at org.apache.curator.framework.imps.ExistsBuilderImpl.pathInForeground(ExistsBuilderImpl.java:158) [curator-framework-2.8.0.jar:na]
     72     at org.apache.curator.framework.imps.ExistsBuilderImpl.forPath(ExistsBuilderImpl.java:148) [curator-framework-2.8.0.jar:na]
     73     at org.apache.curator.framework.imps.ExistsBuilderImpl.forPath(ExistsBuilderImpl.java:36) [curator-framework-2.8.0.jar:na]
     74     at com.alibaba.dubbo.remoting.zookeeper.curator.CuratorZookeeperClient.checkExists(CuratorZookeeperClient.java:117) [dubbo-2.6.2.jar:2.6.2]
     75     at com.alibaba.dubbo.remoting.zookeeper.support.AbstractZookeeperClient.create(AbstractZookeeperClient.java:58) [dubbo-2.6.2.jar:2.6.2]
     76     at com.alibaba.dubbo.registry.zookeeper.ZookeeperRegistry.doRegister(ZookeeperRegistry.java:114) [dubbo-2.6.2.jar:2.6.2]
     77     at com.alibaba.dubbo.registry.support.FailbackRegistry.register(FailbackRegistry.java:131) [dubbo-2.6.2.jar:2.6.2]
     78     at com.alibaba.dubbo.registry.integration.RegistryProtocol.register(RegistryProtocol.java:125) [dubbo-2.6.2.jar:2.6.2]
     79     at com.alibaba.dubbo.registry.integration.RegistryProtocol.export(RegistryProtocol.java:145) [dubbo-2.6.2.jar:2.6.2]
     80     at com.alibaba.dubbo.qos.protocol.QosProtocolWrapper.export(QosProtocolWrapper.java:54) [dubbo-2.6.2.jar:2.6.2]
     81     at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper.export(ProtocolFilterWrapper.java:98) [dubbo-2.6.2.jar:2.6.2]
     82     at com.alibaba.dubbo.rpc.protocol.ProtocolListenerWrapper.export(ProtocolListenerWrapper.java:55) [dubbo-2.6.2.jar:2.6.2]
     83     at com.alibaba.dubbo.rpc.Protocol$Adaptive.export(Protocol$Adaptive.java) [dubbo-2.6.2.jar:2.6.2]
     84     at com.alibaba.dubbo.config.ServiceConfig.doExportUrlsFor1Protocol(ServiceConfig.java:506) [dubbo-2.6.2.jar:2.6.2]
     85     at com.alibaba.dubbo.config.ServiceConfig.doExportUrls(ServiceConfig.java:358) [dubbo-2.6.2.jar:2.6.2]
     86     at com.alibaba.dubbo.config.ServiceConfig.doExport(ServiceConfig.java:317) [dubbo-2.6.2.jar:2.6.2]
     87     at com.alibaba.dubbo.config.ServiceConfig.export(ServiceConfig.java:216) [dubbo-2.6.2.jar:2.6.2]
     88     at com.alibaba.dubbo.config.spring.ServiceBean.onApplicationEvent(ServiceBean.java:123) [dubbo-2.6.2.jar:2.6.2]
     89     at com.alibaba.dubbo.config.spring.ServiceBean.onApplicationEvent(ServiceBean.java:49) [dubbo-2.6.2.jar:2.6.2]
     90     at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) [spring-context-5.0.10.RELEASE.jar:5.0.10.RELEASE]
     91     at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) [spring-context-5.0.10.RELEASE.jar:5.0.10.RELEASE]
     92     at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) [spring-context-5.0.10.RELEASE.jar:5.0.10.RELEASE]
     93     at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:400) [spring-context-5.0.10.RELEASE.jar:5.0.10.RELEASE]
     94     at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:354) [spring-context-5.0.10.RELEASE.jar:5.0.10.RELEASE]
     95     at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:886) [spring-context-5.0.10.RELEASE.jar:5.0.10.RELEASE]
     96     at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:161) [spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
     97     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) [spring-context-5.0.10.RELEASE.jar:5.0.10.RELEASE]
     98     at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) [spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
     99     at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) [spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
    100     at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386) [spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
    101     at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
    102     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1242) [spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
    103     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1230) [spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
    104     at com.sharp.forward.UserServiceApplication.main(UserServiceApplication.java:14) [classes/:na]
    105 
    106 2018-12-02 20:13:32.211  INFO 32764 --- [168.1.105:2181)] org.apache.zookeeper.ClientCnxn          : Opening socket connection to server 192.168.1.105/192.168.1.105:2181. Will not attempt to authenticate using SASL (unknown error)
    107 2018-12-02 20:13:32.213  INFO 32764 --- [168.1.105:2181)] org.apache.zookeeper.ClientCnxn          : Socket connection established to 192.168.1.105/192.168.1.105:2181, initiating session
    108 2018-12-02 20:13:32.241  INFO 32764 --- [168.1.105:2181)] org.apache.zookeeper.ClientCnxn          : Session establishment complete on server 192.168.1.105/192.168.1.105:2181, sessionid = 0x10002652c2f0001, negotiated timeout = 40000
    109 2018-12-02 20:13:32.248  INFO 32764 --- [ain-EventThread] o.a.c.f.state.ConnectionStateManager     : State change: CONNECTED
    110 2018-12-02 20:13:33.823  INFO 32764 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8886 (http) with context path ''
    111 2018-12-02 20:13:33.830  INFO 32764 --- [           main] c.sharp.forward.UserServiceApplication   : Started UserServiceApplication in 22.568 seconds (JVM running for 23.492)
    View Code

    查看dubbo-admin后看到

    服务注册成功,然后就是消费端的架构了

    消费者这块不再需要和数据库有任何交互,也不需要jdbc等相关依赖,所以不需要的部分全部去掉即可pom.xml如下:

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     3     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     4     <modelVersion>4.0.0</modelVersion>
     5 
     6     <artifactId>sharp-user</artifactId>
     7     <packaging>jar</packaging>
     8 
     9     <name>sharp-user</name>
    10     <description>Demo project for Spring Boot</description>
    11 
    12     <parent>
    13         <groupId>com.sharp</groupId>
    14     <artifactId>sharp-pom</artifactId>
    15     <version>0.0.1-SNAPSHOT</version>
    16     </parent>
    17 
    18 
    19     <dependencies>
    20         <dependency>
    21             <groupId>org.springframework.boot</groupId>
    22             <artifactId>spring-boot-starter-web</artifactId>
    23         </dependency>
    24         <dependency>
    25             <groupId>com.sharp</groupId>
    26             <artifactId>sharp-entity</artifactId>
    27             <version>0.0.1-SNAPSHOT</version>
    28         </dependency>
    29         <dependency>
    30             <groupId>com.sharp</groupId>
    31             <artifactId>sharp-common</artifactId>
    32             <version>0.0.1-SNAPSHOT</version>
    33         </dependency>
    34         <dependency>
    35             <groupId>com.sharp</groupId>
    36             <artifactId>sharp-service-api</artifactId>
    37             <version>0.0.1-SNAPSHOT</version>
    38         </dependency>
    39         <!-- 微服务项目使不需要以下实现类的配置,只需要配置好dubbo即可 -->
    40 <!--         <dependency>
    41             <groupId>com.sharp</groupId>
    42             <artifactId>sharp-service</artifactId>
    43             <version>0.0.1-SNAPSHOT</version>
    44         </dependency> -->
    45     <!--     <dependency>
    46             <groupId>com.sharp</groupId>
    47             <artifactId>sharp-mapper</artifactId>
    48             <version>0.0.1-SNAPSHOT</version>
    49         </dependency> -->
    50         <dependency>
    51             <groupId>org.springframework.boot</groupId>
    52             <artifactId>spring-boot-starter-test</artifactId>
    53             <scope>test</scope>
    54         </dependency>
    55         <!-- https://mvnrepository.com/artifact/com.alibaba/dubbo -->
    56         <dependency>
    57             <groupId>com.alibaba</groupId>
    58             <artifactId>dubbo</artifactId>
    59             <exclusions>
    60                 <exclusion>
    61                     <groupId>org.springframework</groupId>
    62                     <artifactId>spring</artifactId>
    63                 </exclusion>
    64             </exclusions>
    65         </dependency>
    66         <dependency>
    67               <groupId>com.101tec</groupId>
    68               <artifactId>zkclient</artifactId>
    69               <version>0.9</version>
    70         </dependency>
    71 
    72     </dependencies>
    73 
    74     <build>
    75         <plugins>
    76             <plugin>
    77                 <groupId>org.springframework.boot</groupId>
    78                 <artifactId>spring-boot-maven-plugin</artifactId>
    79             </plugin>
    80         </plugins>
    81     </build>
    82 
    83 
    84 </project>

    application.properties的数据库和mybatis相关注释掉不需要了

     1 spring.profiles.active=local
     2 
     3 #spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
     4 #spring.datasource.driver-class-name=com.mysql.jdbc.Driver
     5 #spring.datasource.url=jdbc:mysql://192.168.135.129:3306/sharp
     6 #spring.datasource.username=root
     7 #spring.datasource.password=LCY123456lcy!
     8 
     9 #mybatis配置
    10 #指定全局配置文件位置
    11 #mybatis.config-location=classpath:mybatis/mybatis-config.xml
    12 ##指定别名包
    13 #mybatis.type-aliases-package=com.sharp.forward.entity
    14 ##指定xml文件位置
    15 #mybatis.mapper-locations=classpath:mybatis/mapper/*.xml

    application-local

    spring.profiles.active=local

    #mysql连接
    server.port=8887

    dubbo配置

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <beans xmlns="http://www.springframework.org/schema/beans"
     3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
     4     xsi:schemaLocation="
     5         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
     6         http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd"
     7     default-lazy-init="true">
     8     <!-- consumer's application name, used for tracing dependency relationship (not a matching criterion),
     9     don't set it same as provider -->
    10     <dubbo:application name="user"/>
    11     <!-- use multicast registry center to discover service -->
    12     <dubbo:registry protocol="zookeeper" address="zookeeper://127.0.0.1:2181"/>
    13     <!-- generate proxy for the remote service, then demoService can be used in the same way as the
    14     local regular interface -->
    15     <dubbo:reference id="userService" interface="com.sharp.forward.user.service.UserService"/>
    16     
    17 </beans>

    启动类去掉了扫描mapper无用的e

     1 package com.sharp.forward;
     2 
     3 import org.springframework.boot.SpringApplication;
     4 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
     5 import org.springframework.boot.autoconfigure.SpringBootApplication;
     6 import org.springframework.context.annotation.ImportResource;
     7 
     8 @SpringBootApplication
     9 @ImportResource("config/application-user-dubbo.xml")
    10 @EnableAutoConfiguration
    11 public class SharpUserApplication {
    12 
    13     public static void main(String[] args) {
    14         SpringApplication.run(SharpUserApplication.class, args);
    15     }
    16 }

    结构如下:

    然后启动服务,查看注册情况

    正常是服务提供方和消费方均正常

    然后用postman测试也OK

  • 相关阅读:
    Thymeleaf模板引擎绕过浏览器缓存加载静态资源js,css文件
    LCMapString/LCMapStringEx实现简体字、繁体字的转换。
    java8 LocalDateTime转unix时间戳(带毫秒,不带毫秒)
    关于全角半角
    c++builder 读写文件类
    Unresolved external 'AlphaBlend' referenced from
    GridhEH 选择勾CheckBox
    Variant
    TRegEx 正则表达式
    c++ 字符检测 TCharacter
  • 原文地址:https://www.cnblogs.com/xiaoyao-001/p/10055060.html
Copyright © 2011-2022 走看看