A distributed

1.1 What is Distributed

  1. A distributed system must consist of multiple nodes. Nodes refer to computer servers, and these nodes are generally not isolated, but interoperable.
  2. Our nodes are deployed on these connected nodes and their operations will be coordinated. Distributed system for users, they face is a server, to provide users need services, but in fact these services are a distributed system composed of many servers behind, so the distributed system looks like a supercomputer.

1.2 Differences between Distributed and cluster

  1. A cluster is the same system on different servers, such as a login system on different servers.
  2. Distribution is different systems on different servers, servers call each other.

There was only one chef in the restaurant, who cut vegetables, washed vegetables, prepared vegetables and cooked them all. Later, there were too many guests in the kitchen for one cook, so another cook was hired. Both cooks could cook the same dishes. The relationship between the two cooks was cluster. In order to make the chef concentrate on cooking and make the dishes to the extreme, a chef is invited to be responsible for cutting, preparing and preparing vegetables. The relationship between the chef and the chef is distributed, and a chef is too busy to come over, so another chef is invited, and the relationship between the two chefs is cluster. Excerpt from Zhihu, Li Pengfei

2. Build distributed projects

Tools: Eclipse, VMwarm running CentOS7,zookeeper……. And most importantly, a three-year-old machine for the elderly.

1. Create a Maven project with a parent class, packaged as POM.

Create a parent Maven project in Eclipse, packaged as POM. Why create a Maven project with a superclass? Because the maven project is used to manage each jar package version, subclasses that want the jar package directly ask the parent class for.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 - the SNAPSHOT < / version > < packaging > pom < / packaging > <! <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 rainfall distribution on 10-12 < / 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 > <! <dependencyManagement> <dependencies> < <dependencies> <! --> <dependency> <groupId>joda-time</groupId>Copy the code

2. Create a Maven aggregation project.

2.1 Create maven aggregation project and inherit the parent project.

Aggregation project: The controller layer,view layer and so on in the project can be independent into a project, and finally integrated into the operation.

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 - the SNAPSHOT < / version > < / parent > < groupId > com. Itqf < / groupId > < artifactId > sping - manager < / artifactId > <version>0.0.1-SNAPSHOT</version> <packaging> POm </packaging> <dependencies> <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>Copy the code

2.2 Create maven Module in aggregation project and name it Sping-manager-pojo (Entity class layer).

  1. Pojo is a plain JAR format that does not rely on the parent project.

    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 - the SNAPSHOT < / version > < / parent > < artifactId > sping - manager - pojo < / artifactId > < project >Copy the code

2.3 Create a Maven Module in the aggregation project and name it sping-manager-mapper(DAO layer).

  • We rely on pojos in the pom.xml file. Because mapper layer methods return an entity-class object, we need poJOs.
  • Import dependent JAR packages.

    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 - the SNAPSHOT < / version > < / parent > < artifactId > sping - manager - mapper < / artifactId > <! <dependency> <groupId>com.itqf</groupId> <artifactId>sping-manager-pojo</artifactId> The < version > 0.0.1 - the 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> <! Alibaba </groupId> <artifactId>druid</artifactId> <version>${druid.version}</version>
			</dependency>
      
  </dependencies>
</project>
Copy the code

2.4 Create sping-manager-interface(interface) in the aggregation project and put all service interfaces into an independent project.

  • Pojos are required if the return value of an interface method is an entity class. Therefore, POJOs are relied on in POMxml
<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> < the groupId > com. Itqf < / groupId > < artifactId > sping - manager - pojo < / artifactId > < version > 0.0.1 - the SNAPSHOT < / version > < / dependency >  </dependencies> </project>Copy the code

2.5 Create sping-manager-service(interface implementation class) in the aggregation project. The package is war

Since the Controller layer is separated from the Service layer, the Controller and service should be published separately by Tomcat during startup, and the configuration files needed in the aggregation project should be put into the service, so that the configuration files will be added when Tomcat is started Integration.

  • A service needs an interface, so it relies on the sping-manager-interface interface.
  • A service needs to use poJO and also needs to call Mapper, so you can rely on Mapper directly, assuming that mapper already depends on POJO.
  • The service needs to be managed by Spring to create objects for the service
  • Service requires dubbo’s package (more on Dubbo later)
  • Service needs to use SOA and be published as a service.

Configuration file 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>
</configuration>
Copy the code

db.properties

db.driver=com.mysql.jdbc.Driver db.url=jdbc:mysql://localhost:3306/taotao? characterEncoding=UTF-8 db.username=root db.password=rootCopy the code

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.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.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-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>
Copy the code

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.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.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-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>  
Copy the code

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.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.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-4.2.xsd">
    
    <context:component-scan base-package="com.itqf.service"></context:component-scan>   
</beans>

Copy the code

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 < version > 0.0.1 - the 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 - the SNAPSHOT < / version > < / dependency > < the dependency > < groupId > com. Qianfeng < / groupId > < artifactId > sping - manager - mapper < / artifactId > < version > 0.0.1 - the 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>

Copy the code

Final engineering structure


3 Use dubbo to publish the service with service

Think first? Like Taobao jingdong such mall website, not only can log in from the PC side, but also from the mobile phone side login, so how to achieve? Write two controller? No, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no. So when you’re writing a project that’s distributed, you’re going to have a lot of systems calling each other, and if you call back and forth it’s going to mess up the code structure. Here we use Dubbo to manage the confusion caused by too many publishing services.


What is the SOA

SOA is a design approach that includes multiple services that, through coordination, ultimately provide a set of capabilities. A service usually exists in a separate operating system process. Services communicate with each other through network calls rather than in-process calls. For example, you now have many services: News service (provide news release, view, modify, delete), order service (order to add, modify orders, order check, order delete etc.), financial service (income, spending, statistics, etc.) the staff service (add, modify, check, statistics) attendance service (sign in and sign out, export, statistics, etc.) sales and service (sell report, sales statistics.

Advantages and disadvantages of SOA

Reference: benefits, cons, and embarrassments of SOA


dubbo

With the development of the Internet and the continuous expansion of the scale of web applications, the conventional vertical application architecture has been unable to cope with it. Distributed service architecture and mobile computing architecture are imperative, and a governance system is urgently needed to ensure the orderly evolution of the architecture.

  • Single application Architecture
    • When site traffic is low, only one application is needed to deploy all functions together to reduce deployment nodes and costs.
    • At this point, data access frameworks (ORM) that simplify the work of adding, deleting, modifying and reviewing are key.
  • Vertical application Architecture
    • When the volume of traffic gradually increases, the acceleration caused by the increase of a single application machine is getting smaller and smaller. The application is divided into several unrelated applications to improve efficiency.
    •  The Web framework (MVC) for accelerating front-end page development is key at this point.
  • Distributed Service Architecture
    • With the increasing number of vertical applications, the interaction between applications is inevitable. Core businesses are extracted as independent services, gradually forming a stable service center, so that front-end applications can respond to changing market demands more quickly.
    • At this point, the distributed Services framework (RPC) for business reuse and integration is key.
  • Mobile Computing Architecture
    • As the number of services increases, problems such as capacity evaluation and waste of small service resources gradually emerge. In this case, a scheduling center needs to be added to manage cluster capacity in real time based on access pressure to improve cluster utilization.
    • At this point, a resource scheduling and Governance center (SOA) for improving machine utilization is key. Construction of Dubbo environment:

Node roles:

  • Provider: exposes the service Provider of the service.
  • Consumer: Service Consumer that invokes the remote service.
  • Registry: A Registry where services are registered and discovered.
  • Monitor: monitors the number and duration of service invocation.
  • Container: service running Container.

Call relationship description:

  1. The service container is responsible for starting, loading, and running the service provider.
  2. At startup, service providers register their services with the registry.
  3. At startup, service consumers subscribe to the registry for the services they need.
  4. The registry returns a list of service provider addresses to the consumer, and if there are changes, the registry pushes the change data to the consumer based on the long connection.
  5. The service consumer, from the provider address list, selects one provider to call based on the soft load balancing algorithm. If the call fails, selects another one to call.
  6. Service consumers and providers accumulate calls and call times in memory and regularly send statistics to the monitoring center every minute.

Here we mainly use the Registry, and we use Zookeeper to act as the Registry.

Deploy the registry and Zookeeper in a Linux environment

  1. The first step, of course, is to start the virtual machine, which I will do in CentOS7.
  2. Go online and get a Zookeeper zip package. Mine is Zookeeper-3.4.6.tar. gz
  3. Paste it into the /opt directory and decompress it.
  4. Go to the zookeeper-3.4.6 directory and create a folder called data.
  5. Rename zoo_sample. CFG in the./conf directory to zoo.cfg
  6. CFG: dataDir=/opt/zookeeper-3.4.6/data
  7. Step 7: Start ZooKeeper.
    • Activation:. / zkServer. Sh start
    • Close:. / zkServer. Sh stop
    • Run the./zkServer.sh status command to check the status

Turn off the firewall after ZooKeeper starts!! And we’re done.

Add a configuration file to the applicationContext-service.xml of the service to publish the service

<! Publish services using Dubbo --> <! <dubbo:application name="sping-manager"/ > <! <dubbo:registry protocol= <dubbo:registry protocol="zookeeper" address="10.0.117.198:2181"></dubbo:registry> <! --> <dubbo:protocol name="dubbo" port="20888"></dubbo:protocol> <! <dubbo: Service interface= dubbo: Service interface="com.itqf.service.ItemService" ref="itemServiceImpl" timeout="6000000"></dubbo:service>
Copy the code

Import the package in the service’s pom.xml

<! -- dubbo related --> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <! --> <exclusions> <groupId>org.spring Framework </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>Copy the code

4 Create a sping-manager-Controller level with the aggregate project. Import dependencies.

Contoller needs to use Dubbo to access services published by the Service layer. To publish using the Tomcat server, of course, you also need to use SpringMVC.xml

<dependencies> <! </artifactId> sping-manager-interface</artifactId> The < version > 0.0.1 - the 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> <! JSTL </artifactId> </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 related --> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <! --> <exclusions> <groupId>org.spring Framework </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>Copy the code

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.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.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-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"/ > <! -- Specify the registry --> <dubbo: Registry protocol="zookeeper" address="10.0.117.198:2181"></dubbo:registry> <! <dubbo: Reference interface="com.itqf.service.ItemService" id="itemService"></dubbo:reference>
        
</beans>
Copy the code

Structure:

5 create sping – common

This is a special place for tools that I need to use. This place is used to put some things that are needed by the public. 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 - the SNAPSHOT < / version > < / parent > < groupId > com. Itqf < / groupId > < artifactId > sping - common < / artifactId > The < version > 0.0.1 - the SNAPSHOT < / version > < dependencies > <! --> <dependency> <groupId>joda-time</ artifactId> <version>${joda-time.version}</version> </dependency> <! Commons -lang3</artifactId> <version> Commons </artifactId>${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 processing toolkit - > < the dependency > < groupId > com. Fasterxml. Jackson. Core < / groupId > <artifactId>jackson-databind</artifactId> <version>${jackson.version}</version>
			</dependency>
	</dependencies>
  
</project>
Copy the code

6 test

Now that a pseudo-distributed project is set up, it is very important to install the parent project, the sping-manager aggregation project, and sping-common into the local repository, otherwise the project will start up with an error saying that the parent project or other projects could not be found. Final engineering drawing:

Conclusion:

It took hours of hard work to build it, and my old man was about to explode. If there are any mistakes or deficiencies, please do not hesitate to tell me.