java实现分布式项目搭建

article/2025/9/16 2:53:49

1 分布式

 1.1 什么是分布式

  1. 分布式系统一定是由多个节点组成的系统。其中,节点指的是计算机服务器,而且这些节点一般不是孤立的,而是互通的。
  2. 这些连通的节点上部署了我们的节点,并且相互的操作会有协同。分布式系统对于用户而言,他们面对的就是一个服务器,提供用户需要的服务而已,而实际上这些服务是通过背后的众多服务器组成的一个分布式系统,因此分布式系统看起来像是一个超级计算机一样。

1.2 分布式与集群的区别

  1. 集群是同一个系统部在不同的服务器上,例如一个登陆系统部在不同的服务器上.
  2. 分布式是不同的系统部在不同的服务器上,服务器之间相互调用.

小饭店原来只有一个厨师,切菜洗菜备料炒菜全干。后来客人多了,厨房一个厨师忙不过来,又请了个厨师,两个厨师都能炒一样的菜,这两个厨师的关系是集群。为了让厨师专心炒菜,把菜做到极致,又请了个配菜师负责切菜,备菜,备料,厨师和配菜师的关系是分布式,一个配菜师也忙不过来了,又请了个配菜师,两个配菜师关系是集

2 搭建分布式项目

准备工具:eclipse,装有CentOS7系统的VMwarm,zookeeper.......最重要的,一台三年高龄的老人机.

1 首先创建一个父类的maven项目,打包方式为pom.

在eclipse中创建一个父类maven项目,打包方式为pom.为什么要创建一个父类的maven项目呢?因为要使用这个maven项目进行各个jar包版本的管理,子类想要jar包直接跟父类要就可以. xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.itqf</groupId><artifactId>sping-parent</artifactId><version>0.0.1-SNAPSHOT</version><packaging>pom</packaging><!-- 定义所有jar包的版本 --><properties><junit.version>4.12</junit.version><spring.version>4.2.4.RELEASE</spring.version><mybatis.version>3.2.8</mybatis.version><mybatis.spring.version>1.2.2</mybatis.spring.version><mybatis.paginator.version>1.2.15</mybatis.paginator.version><mysql.version>5.1.32</mysql.version><slf4j.version>1.6.4</slf4j.version><jackson.version>2.4.2</jackson.version><druid.version>1.0.9</druid.version><httpclient.version>4.3.5</httpclient.version><jstl.version>1.2</jstl.version><servlet-api.version>2.5</servlet-api.version><jsp-api.version>2.0</jsp-api.version><joda-time.version>2.5</joda-time.version><commons-lang3.version>3.3.2</commons-lang3.version><commons-io.version>1.3.2</commons-io.version><commons-net.version>3.3</commons-net.version><pagehelper.version>3.4.2-fix</pagehelper.version><jsqlparser.version>0.9.1</jsqlparser.version><commons-fileupload.version>1.3.1</commons-fileupload.version><jedis.version>2.7.2</jedis.version><solrj.version>4.10.3</solrj.version><dubbo.version>2.5.3</dubbo.version><zookeeper.version>3.4.7</zookeeper.version><zkclient.version>0.1</zkclient.version><activemq.version>5.11.2</activemq.version><freemarker.version>2.3.23</freemarker.version><quartz.version>2.2.2</quartz.version></properties><!-- 管理所有项目中用到的jar包,并不做真正的依赖 --><dependencyManagement><dependencies><!-- 时间操作组件 --><dependency><groupId>joda-time</groupId>
复制代码

2 创建一个maven的聚合工程.

2.1 创建maven聚合工程,继承父工程.

聚合工程:可以将项目中的controller层,view层等都独立成一个工程,最终运行的时候整合到一起运行.

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>com.itqf</groupId><artifactId>sping-parent</artifactId><version>0.0.1-SNAPSHOT</version></parent><groupId>com.itqf</groupId><artifactId>sping-manager</artifactId><version>0.0.1-SNAPSHOT</version><packaging>pom</packaging><dependencies><dependency><groupId>com.itqf</groupId><artifactId>sping-common</artifactId><version>0.0.1-SNAPSHOT</version></dependency></dependencies><build><plugins><plugin><groupId>org.apache.tomcat.maven</groupId><artifactId>tomcat7-maven-plugin</artifactId><configuration><port>8083</port><path>/</path></configuration></plugin></plugins></build><modules><module>sping-manager-pojo</module><module>sping-manager-interface</module><module>sping-manager-service</module><module>sping-manager-mapper</module></modules>
</project>
复制代码

2.2 在聚合工程中创建maven Module,命名sping-manager-pojo(实体类层).

  1. pojo是一个普通的jar格式,不需要依赖父工程.
    pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>com.itqf</groupId><artifactId>sping-manager</artifactId><version>0.0.1-SNAPSHOT</version></parent><artifactId>sping-manager-pojo</artifactId>
</project>
复制代码

2.3 在聚合工程中创建maven Module,命名sping-manager-mapper(dao层).

  • 在pom.xml文件中依赖pojo.因为mapper层的方法返回的是一个实体类对象的话,那么需要用到pojo.
  • 导入依赖jar包.
    xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>com.itqf</groupId><artifactId>sping-manager</artifactId><version>0.0.1-SNAPSHOT</version></parent><artifactId>sping-manager-mapper</artifactId><!-- 依赖pojo --><dependencies><dependency><groupId>com.itqf</groupId><artifactId>sping-manager-pojo</artifactId><version>0.0.1-SNAPSHOT</version></dependency><!-- Mybatis --><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>${mybatis.version}</version></dependency><dependency><groupId>org.mybatis</groupId><artifactId>mybatis-spring</artifactId><version>${mybatis.spring.version}</version></dependency><dependency><groupId>com.github.miemiedev</groupId><artifactId>mybatis-paginator</artifactId><version>${mybatis.paginator.version}</version></dependency><dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper</artifactId><version>${pagehelper.version}</version></dependency><!-- MySql --><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>${mysql.version}</version></dependency><!-- 连接池 --><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>${druid.version}</version></dependency></dependencies>
</project>
复制代码

2.4 在聚合工程中创建sping-manager-interface(接口),将所有的service接口都放到独立的工程当中.

  • 接口中方法返回值如果是实体类,需要用到pojo.所以在pom中依赖pojo xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>com.itqf</groupId><artifactId>sping-manager</artifactId><version>0.0.1-SNAPSHOT</version></parent><artifactId>sping-manager-interface</artifactId><dependencies><dependency><groupId>com.itqf</groupId><artifactId>sping-manager-pojo</artifactId><version>0.0.1-SNAPSHOT</version></dependency></dependencies></project>
复制代码

2.5 在聚合项目中创建sping-manager-service(interface的实现类).打包方式为war

因为将controller层与service层分开了,所以在运行启动的时候要讲controller和service单独使用tomcat发布,将聚合工程中所需要的配置文件都放入service中,这样在Tomcat启动的时候回将配置文件都进行加载整合.

  • service需要用到接口,所以依赖接口sping-manager-interface.
  • service需要用到pojo,也需要调用到mapper,所以直接依赖mapper就可以,以为mapper已经依赖了pojo (依赖传递).
  • service需要被spring管理,让spring给service创建对象
  • service需要dubbo的包(后面对dubbo进行介绍)
  • service需要使用到SOA,将service当成一个服务发布出去.

配置文件
SqlMapConfig.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
</configuration>
复制代码

db.properties

db.driver=com.mysql.jdbc.Driver
db.url=jdbc:mysql://localhost:3306/taotao?characterEncoding=UTF-8
db.username=root
db.password=root
复制代码

applicationContext-tx.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:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:tx="http://www.springframework.org/schema/tx"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsdhttp://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-4.2.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-4.2.xsdhttp://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd"><bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource"></property></bean>     <tx:advice id="adviceId" transaction-manager="txManager"><tx:attributes><tx:method name="add*" propagation="REQUIRED"/><tx:method name="save*" propagation="REQUIRED"/><tx:method name="insert*" propagation="REQUIRED"/><tx:method name="update*" propagation="REQUIRED"/><tx:method name="del*" propagation="REQUIRED"/><tx:method name="find*" propagation="SUPPORTS" read-only="true"/><tx:method name="get*" propagation="SUPPORTS" read-only="true"/></tx:attributes></tx:advice><aop:config><aop:advisor advice-ref="adviceId" pointcut="execution(* com.itqf.service..*.*(..))"/></aop:config>     </beans>
复制代码

applicationContext-dao.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:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsdhttp://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsdhttp://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd"><context:property-placeholder location="classpath:resource/*.properties"/><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"><property name="driverClassName" value="${db.driver}"></property><property name="url" value="${db.url}"></property><property name="username" value="${db.username}"></property><property name="password" value="${db.password}"></property><property name="maxActive" value="10"></property><property name="minIdle" value="5"></property></bean><bean class="org.mybatis.spring.SqlSessionFactoryBean"><property name="dataSource" ref="dataSource"></property><property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml"></property></bean><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><property name="basePackage" value="com.itqf.mapper"></property></bean></beans>  
复制代码

applicationContext-service.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:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsdhttp://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsdhttp://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd"><context:component-scan base-package="com.itqf.service"></context:component-scan>   
</beans>复制代码

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>com.qianfeng</groupId><artifactId>sping-manager</artifactId><version>0.0.1-SNAPSHOT</version></parent><artifactId>sping-manager-service</artifactId><packaging>war</packaging><dependencies><dependency><groupId>com.qianfeng</groupId><artifactId>sping-manager-interface</artifactId><version>0.0.1-SNAPSHOT</version></dependency><dependency><groupId>com.qianfeng</groupId><artifactId>sping-manager-mapper</artifactId><version>0.0.1-SNAPSHOT</version></dependency><!-- Spring --><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-beans</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-aspects</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-jms</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-context-support</artifactId><version>${spring.version}</version></dependency></dependencies>
</project>复制代码

最后工程结构


3 使用dubbo将service发布服务

首先思考?
像淘宝京东这样的商城类网站,不但可以从PC端登录,还能从手机端登录,那么是怎么实现的?写两个controller?那肯定不会,谁会闲着没事去找事情做,那么这就需要使用到SOA(面向服务的架构).那么我们在写一个项目使用分布式的时候,会有很多系统来相互调用,如果来回调用会使代码结构非常混乱.这里我们使用dubbo来管理,解决发布服务太多,搞不清楚的问题.


什么是SOA

SOA是一种设计方法,其中包含多个服务,而服务之间通过配合最终会提供一系列功能。一个服务通常以独立的形式存在于操作系统进程中。服务之间通过网络调用,而非采用进程内调用的方式进行通信。
比如你现在有很多服务:新闻服务(提供新闻的发布,查看,修改,删除),订单服务(订单添加,订单修改,订单查看,订单删除等)财务服务(收入,支出,统计等等)员工服务(新增,修改,查看,统计)考勤服务(签到,签退,导出,统计等)销售服务(卖出上报,销售统计。)

SOA的优缺点


dubbo

什么是dubbo(是资源调度和治理中心的管理工具)
随着互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,亟需一个治理系统确保架构有条不紊的演进。

  • 单一应用架构
    • 当网站流量很小时,只需一个应用,将所有功能都部署在一起,以减少部署节点和成本。
    • 此时,用于简化增删改查工作量的 数据访问框架(ORM) 是关键。
  • 垂直应用架构
    • 当访问量逐渐增大,单一应用增加机器带来的加速度越来越小,将应用拆成互不相干的几个应用,以提升效率。
    • 此时,用于加速前端页面开发的 Web框架(MVC) 是关键。
  • 分布式服务架构
    • 当垂直应用越来越多,应用之间交互不可避免,将核心业务抽取出来,作为独立的服务,逐渐形成稳定的服务中心,使前端应用能更快速的响应多变的市场需求。
    • 此时,用于提高业务复用及整合的 分布式服务框架(RPC) 是关键。
  • 流动计算架构
    • 当服务越来越多,容量的评估,小服务资源的浪费等问题逐渐显现,此时需增加一个调度中心基于访问压力实时管理集群容量,提高集群利用率。
    • 此时,用于提高机器利用率的 资源调度和治理中心(SOA) 是关键。 Dubbo环境的搭建:

 

节点角色说明:

  • Provider: 暴露服务的服务提供方。
  • Consumer: 调用远程服务的服务消费方。
  • Registry: 服务注册与发现的注册中心。
  • Monitor: 统计服务的调用次数和调用时间的监控中心。
  • Container: 服务运行容器。

调用关系说明:

  1. 服务容器负责启动,加载,运行服务提供者。
  2. 服务提供者在启动时,向注册中心注册自己提供的服务。
  3. 服务消费者在启动时,向注册中心订阅自己所需的服务。
  4. 注册中心返回服务提供者地址列表给消费者,如果有变更,注册中心将基于长连接推送变更数据给消费者。
  5. 服务消费者,从提供者地址列表中,基于软负载均衡算法,选一台提供者进行调用,如果调用失败,再选另一台调用。
  6. 服务消费者和提供者,在内存中累计调用次数和调用时间,定时每分钟发送一次统计数据到监控中心。

这里我们主要来部注册中心(Registry),我们使用Zookeeper来充当注册中心.

在linux环境下部署注册中心,Zookeeper

  1. 第一步当然是开虚拟机啦,我还是在CentOS7中来搞.
  2. 上网上搞一个Zookeeper的压缩包,我的是zookeeper-3.4.6.tar.gz
  3. 粘贴到/opt目录下,解压.(需要jdk环境,如果没有jdk环境先安装一个jdk)
  4. 进入zookeeper-3.4.6目录,创建一个叫data的文件夹。
  5. 把./conf目录下的zoo_sample.cfg改名为zoo.cfg
  6. 修改zoo.cfg中的data属性:dataDir=/opt/zookeeper-3.4.6/data
  7. 第七步:启动zookeeper.
    • 启动:./zkServer.sh start
    • 关闭:./zkServer.sh stop
    • 查看状态:./zkServer.sh status

注意zookeeper启动后一定要将防火墙关闭!!!这样就搞定啦.

在service的applicationContext-service.xml中添加配置文件进行发布服务

<!-- 使用dubbo发布服务 -->  <!-- 指明服务所在的工程 -->  <dubbo:application name="sping-manager"/><!-- 指明注册中心 adress地址是linux中的ip地址加上端口号,zookeeper的默认端口号是2181 --><dubbo:registry protocol="zookeeper" address="10.0.117.198:2181" ></dubbo:registry><!-- 把服务暴露在某个端口 port是端口号,选择一个没有被占用的端口 -->  <dubbo:protocol name="dubbo" port="20888"></dubbo:protocol>  <!-- 发布服务,ref是Spring容器创建的Service对象的名称 -->    			 <dubbo:service interface="com.itqf.service.ItemService" ref="itemServiceImpl" timeout="6000000"></dubbo:service>
复制代码

在service的pom.xml中导入包

  <!-- dubbo相关 --><dependency><groupId>com.alibaba</groupId><artifactId>dubbo</artifactId><!-- 排除依赖 --><exclusions><exclusion><groupId>org.springframework</groupId><artifactId>spring</artifactId></exclusion><exclusion><groupId>org.jboss.netty</groupId><artifactId>netty</artifactId></exclusion></exclusions></dependency><dependency><groupId>org.apache.zookeeper</groupId><artifactId>zookeeper</artifactId></dependency><dependency><groupId>com.github.sgroschupf</groupId><artifactId>zkclient</artifactId></dependency>
复制代码

4 创建一个sping-manager-controller,与聚合项目平级.导入依赖.

contoller需要使用dubbo来访问service层发布的服务.要使用Tomcat服务器进行发布,当然还需要用到springmvc.
xml

  <dependencies><!-- 只需依赖业务的接口 --><dependency><groupId>com.qianfeng</groupId><artifactId>sping-manager-interface</artifactId><version>0.0.1-SNAPSHOT</version></dependency><!-- Spring --><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-beans</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-aspects</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-jms</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-context-support</artifactId><version>${spring.version}</version></dependency><!-- JSP相关 --><dependency><groupId>jstl</groupId><artifactId>jstl</artifactId></dependency><dependency><groupId>javax.servlet</groupId><artifactId>servlet-api</artifactId><scope>provided</scope></dependency><dependency><groupId>javax.servlet</groupId><artifactId>jsp-api</artifactId><scope>provided</scope></dependency><!-- dubbo相关 --><dependency><groupId>com.alibaba</groupId><artifactId>dubbo</artifactId><!-- 排除依赖 --><exclusions><exclusion><groupId>org.springframework</groupId><artifactId>spring</artifactId></exclusion><exclusion><groupId>org.jboss.netty</groupId><artifactId>netty</artifactId></exclusion></exclusions></dependency><dependency><groupId>org.apache.zookeeper</groupId><artifactId>zookeeper</artifactId></dependency><dependency><groupId>com.github.sgroschupf</groupId><artifactId>zkclient</artifactId></dependency></dependencies><build><plugins><plugin><groupId>org.apache.tomcat.maven</groupId><artifactId>tomcat7-maven-plugin</artifactId><configuration><port>8081</port><path>/</path></configuration></plugin></plugins></build>
复制代码

spingmvc.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:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:tx="http://www.springframework.org/schema/tx"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsdhttp://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-4.2.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-4.2.xsdhttp://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd"><context:component-scan base-package="com.itqf.controller"></context:component-scan><mvc:annotation-driven></mvc:annotation-driven><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/WEB-INF/jsp/"></property><property name="suffix" value=".jsp"></property></bean><!--指明所在工程 --><dubbo:application name="sping-manager-controller"/><!-- 指明注册中心 --><dubbo:registry protocol="zookeeper" address="10.0.117.198:2181"></dubbo:registry><!--调用服务  --><dubbo:reference interface="com.itqf.service.ItemService" id="itemService"></dubbo:reference></beans>
复制代码

5 创建sping-common

这个是我需要用到的一个专门放工具的地方,这里用来放一些公共需要的东西; pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>com.itqf</groupId><artifactId>sping-parent</artifactId><version>0.0.1-SNAPSHOT</version></parent><groupId>com.itqf</groupId><artifactId>sping-common</artifactId><version>0.0.1-SNAPSHOT</version><dependencies><!-- 时间操作组件 --><dependency><groupId>joda-time</groupId><artifactId>joda-time</artifactId><version>${joda-time.version}</version></dependency><!-- Apache工具组件 --><dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId><version>${commons-lang3.version}</version></dependency><dependency><groupId>org.apache.commons</groupId><artifactId>commons-io</artifactId><version>${commons-io.version}</version></dependency><dependency><groupId>commons-net</groupId><artifactId>commons-net</artifactId><version>${commons-net.version}</version></dependency><!-- Jackson Json处理工具包 --><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId><version>${jackson.version}</version></dependency></dependencies></project>
复制代码

6 测试

好啦,这样一个伪分布式项目就搭建好了,接下来非常重要的一点就是需要将父工程,sping-manager的聚合工程,sping-common都install一下放到本地仓库中,否则的话在启动项目的时候会报错说找不到父工程或其他工程.
最终工程图:

总结:

经过几个小时的艰苦奋战终于搭建好了,都要给我的老人机累炸了.如果有什么错误或不足之处请不吝之处.


http://chatgpt.dhexx.cn/article/9Ljd81sh.shtml

相关文章

分布式专题(2)- 分布式 Java通信

本篇一句话总结&#xff1a;Java实现分布式通信&#xff0c;可以基于Java API、开源框架和远程通信技术三种方式实现。 正文开始&#xff1a; 通过上一篇文章《分布式专题&#xff08;1&#xff09;- 计算机网络》我们知道了计算机之间之所以能够进行通信的原理。如果对计算机网…

java简单搭建分布式架构

一般来说&#xff0c;数据库的数据过多&#xff0c;查询效率就很慢&#xff0c;这时候我们如果把表分库到不同的数据库&#xff0c;这时候访问速度就会快很多&#xff0c;如果并且采用多线程去访问的话&#xff0c;查询速度也会提高的更快&#xff0c;我这里是运行内存8核电脑进…

java实现分布式项目搭建的方法

1 分布式 1.1 什么是分布式 分布式系统一定是由多个节点组成的系统。其中&#xff0c;节点指的是计算机服务器&#xff0c;而且这些节点一般不是孤立的&#xff0c;而是互通的。这些连通的节点上部署了我们的节点&#xff0c;并且相互的操作会有协同。分布式系统对于用户而言…

java分布式技术平台架构方案

CoolJava技术特点 CoolJava的技术解决方案信息系统的稳定性、技术先进性、可拓展性&#xff0c;并且满足未来继续增长、业务变革、监管加强的潜在需求。追求系统快速开发迭代&#xff0c;CoolJava应用开发框架能3倍以上速度&#xff0c;完成系统开发。系统平台具有较大的灵活调…

java 分布式介绍

java分布式服务框架Dubbo的介绍与使用 1. Dubbo是什么&#xff1f; Dubbo是一个分布式服务框架&#xff0c;致力于提供高性能和透明化的RPC远程服务调用方案&#xff0c;以及SOA服务治理方案。简单的说&#xff0c;dubbo就是个服务框架&#xff0c;如果没有分布式的需求&#x…

深入浅出Java开发!什么是分布式系统,如何学习分布式系统

欢迎关注专栏&#xff1a;Java架构技术进阶。里面有大量batj面试题集锦&#xff0c;还有各种技术分享&#xff0c;如有好文章也欢迎投稿哦。 什么是分布式系统 分布式系统是由一组通过网络进行通信、为了完成共同的任务而协调工作的计算机节点组成的系统。分布式系统的出现是为…

分布式-Java应用

分布式计算不是一门年轻的技术&#xff0c;早在上个世纪70年代末便已是计算机科学的一个独立分支了&#xff1b;它也不是一门冷僻的技术&#xff0c;从C/S模式到P2P模式&#xff0c;从集群计算到网格计算&#xff0c;乃至风靡当下的云计算&#xff0c;都是其表演的舞台。另一方…

分布式开发简介

分布式开发简介 1 概述 分布式应用程序就是指应用程序分布在不同计算机上&#xff0c;通过网络来共同完成一项任务&#xff0c;通常为服务器/客户端模式。更广义上理解“分布”&#xff0c;不只是应用程序&#xff0c;还包括数据库等&#xff0c;分布在不同计算机&a…

java分布式学习

首先推荐4本书 大型分布式网站架构设计与实践 http://item.jd.com/11529266.html 大型网站技术架构&#xff1a;核心原理与案例分析 http://item.jd.com/11322972.html 大型网站系统与Java中间件实践 http://item.jd.com/11449803.html 分布式Java应用&#xff1a;基础与实践 h…

耗时十年!精心整理的Java高级开发需要的分布式技术

前言 分布式、微服务几乎是现在的技术人员必须要了解的架构方向&#xff0c;从理论上来讲确实解耦了很多结构&#xff0c;但另一方面&#xff0c;又会带来更多衍生的复杂度及难点。 如何保证事物的最终一致性&#xff1f;如何进行性能及容量预估&#xff1f;如何处理分布式系统…

Java分布式开发

分布式概念的引入是基于性能的提升&#xff0c;应用的可靠性而提出的。所谓Java分布式&#xff0c;即是在使用Java语言进行企业级应用开发的过程中&#xff0c;采用分布式技术解决业务逻辑的高并发、高可用性的一些架构设计方案。 1. RPC技术介绍 我们知道Web Servie实现了服务…

足球赛事实时大小球数据worldliveball软件搭建

worldliveball软件 worldliveball开发思路功能脑图合理的展示足球赛事如何快捷的判断赛事wordliveball下载地址与软件图片代码宏定义运用了哪些技术worldliveball流程图 worldliveball 整个足球赛事AI worldliveball 开发思路及过程。如果你想学习如何使用worldliveball, 可以…

足球走地大小球预测-分析软件开发及逻辑

足球大小球分析之大球 相比小球&#xff0c;热爱大球玩法的更多。走地大小球&#xff0c;预测进球数简单明了。无论比赛双方哪一方进球&#xff0c;对于您而言&#xff0c;都是欢喜的。只要进球数量达到了&#xff0c;您就妥妥的了。 走地大球玩法之挑赛事 那么有些赛事疯狂进…

足球走地大小球预测之理性分析软件开发及逻辑

足球走地大小球 前言一、足球大小球分析之小球二、走地大小球分析之看实时数据1.实时数据2.足球分析逻辑 AI足球数据 前言 足球已经开始了也快百年了&#xff0c;但市面上没有真正好的分析的&#xff0c;15年开发经验&#xff0c;弄个Ai分析&#xff0c;看看是不是这样的。 一…

足球分析大小球开发成量化交易软件

足球分析大小球量化交易软件 最近总有朋友问足球大小球的那些所谓的分析法则到底准不准&#xff0c;到底该如何去分析大小球究竟是大球还是小球呢&#xff0c;大家都知道股票有量化交易系统&#xff0c;能否开发足球量化交易软件&#xff0c;整理一些多年开发的心得总结出一套…

足球走地大小球量化分析方法软件

前阵子看了国足的比赛后突发奇想&#xff0c;足球的大小是否可以预测呢。于是乎翻遍了各种材料&#xff0c;经过数月的鏖战&#xff0c;结合数据采集大数据分析大小球技巧经验模型机器学习&#xff0c;搞出了一套可以在走地过程中自动分析比赛大小的软件&#xff0c;目前试水挂…

短信/语音在医疗领域(his系统)各场景的应用

短信/语音通知&#xff0c;可广泛应用于医疗领域的内部管理、患者服务等各种应用场景 一、预约挂号 二、远程医疗 三、系统监控 四、网络医嘱 五、体检报告 六、订单提醒 七、信息化办公 八、患者关怀

医院信息管理系统源码 HIS系统源码

系统功能简介&#xff1a; 一、医院门诊模块 门诊&#xff08;预约&#xff09;挂号系统 门诊挂号系统实现了医院门诊部挂号处所需的各种功能。 包括现场办卡&#xff0c;现场挂退号&#xff0c;临时加号&#xff0c;特殊加号&#xff0c;修改患者信息&#xff0c;就诊卡号打…

基层区域应用平台为目标开发的基础医疗云HIS系统源码

系统特点: JAVA语言开发&#xff0c;MYSQL数据库&#xff0c;B/S架构 基于云计算技术的低成本基层医疗信息系统&#xff0c;能够有效降低基层医疗单位信息化建设的投入&#xff0c; 减少系统的维护费用&#xff1b;规范医疗信息、规范业务处理流程&#xff0c;提高服务水平&…

his系统管理工具配置服务器,HIS系统(his管理系统)V3.0.1 官网版

HIS系统(his管理系统)是一款非常专业的his管理程序。行心HIS系统源于北美技术&#xff0c;经过17年HIS技术沉淀&#xff0c;现已拥有100多套子系统&#xff0c;十四项著作权&#xff0c;100多人技术团队。行心HIS系统已经经过300多家医院见证&#xff0c;成熟HIS系统采用专人驻…