Springboot Multi-module--Splitting the web out-flow computing architecture

Source: Internet
Author: User
Tags zookeeper jboss

Preface:

Previously, the layers were split out as a separate, replaceable sub-module. It feels more flexible than it used to be.

Whether it's an e-commerce project or a project that is now being done by the company, there are a lot of business logic that are the same, but because not in a system, you need to do repetitive work. Some copies are OK, but there is no direct copy. It's quite a sore egg. Can you separate the business logic for all the presentation layers?

Is it possible to use the Dubbo described in the previous article?

Framework Retrofit:

In the previous article, through the multi-module, each layer is split out, each become a separate project. Here, before the first slightly modified under, mainly changed the project name, add a common project, put some common things.

Common I built it with Springboot, but commented out the entrance. Here, in addition to the Web has an entry program, the other entrances are all commented out.

  

After the modified directory structure:

  

It is important to note that the portal program in the service is opened, the Application.yml file is created, and all of the configuration parts of the MyBatis are migrated to the service, including Mybatisconfig and Mybatismapperscannerconfig.

Migration Oh, not copy. These things are not needed on the web side.

The concrete transformation process, will not post, the code I will upload to the code cloud. Address: Https://gitee.com/elvinle/bookshop/tree/master/bookshop

Integrated Dubbo Zookeeper:

1. Business Layer Transformation--service side

Pom.xml Add:

<!--Dubbo Related -<!--Https://mvnrepository.com/artifact/com.gitee.reger/spring-boot-starter-dubbo -<Dependency>    <groupId>Com.gitee.reger</groupId>    <Artifactid>Spring-boot-starter-dubbo</Artifactid>    <Exclusions>        <exclusion>            <groupId>Org.jboss.netty</groupId>            <Artifactid>Netty</Artifactid>        </exclusion>    </Exclusions></Dependency>

APPLICATION.YML:

Spring:  Dubbo:    application:bookshop_provider    registry:      address:192.168.153.129      Protocol: Zookeeper      port:2181    protocol:      Name:dubbo      port:20880    base-package: Cn.elvinle.manager.simpl

Application: Name yourself to take one can, do not repeat just fine.

Address: The computer IP of the previous zookeeper deployment.

Port number of the Port:zookeeper service

Registry.protocol: Registration Agreement, zookeeper Registry, default 2181 port

Dubbo.protocol: service agreement, using Dubbo

Dubbo.port: Service port, default 20880

Timeout: Call timed out, default is 1000ms.

Base-package: The package the client is scanning

This is a stand-alone deployment, with no zookeeper cluster. If there is a chance at the back, it will be used.

Code Transformation:

 PackageCn.elvinle.manager.simpl;ImportCn.elvinle.manager.dao.mapper.UserMapper;ImportCn.elvinle.manager.pojo.User;ImportCn.elvinle.manager.service.UserService;ImportCom.alibaba.dubbo.config.annotation.Service;Importorg.springframework.beans.factory.annotation.Autowired;Importjava.util.List;@Service Public classUsersimplImplementsUserService {@AutowiredPrivateUsermapper Usermapper; @Override PublicList<user>GetAll () {List<User> list =Usermapper.getall (); System.out.println ("Server read to data:" +list); returnlist; }}

There seems to be no difference here, but the Service note here is not the one before, but the Com.alibaba.dubbo.config.annotation.Service

2. Web Integration--Client

Pom.xml file Join reference:

<!--Dubbo Related -<!--Https://mvnrepository.com/artifact/com.gitee.reger/spring-boot-starter-dubbo -<Dependency>    <groupId>Com.gitee.reger</groupId>    <Artifactid>Spring-boot-starter-dubbo</Artifactid>    <Exclusions>        <exclusion>            <groupId>Org.jboss.netty</groupId>            <Artifactid>Netty</Artifactid>        </exclusion>    </Exclusions></Dependency>

Application.yml

Spring:  Dubbo:    application:web_consumer    registry:      address:192.168.153.129      Protocol: Zookeeper      port:2181    base-package:cn.elvinle.manager.web.controller    Consumer:      

Code Transformation:

 PackageCn.elvinle.web.controller;ImportCn.elvinle.manager.pojo.User;ImportCn.elvinle.manager.service.UserService;Importcom.alibaba.dubbo.config.annotation.Reference;Importorg.springframework.web.bind.annotation.GetMapping;Importorg.springframework.web.bind.annotation.RequestMapping;ImportOrg.springframework.web.bind.annotation.RestController;Importjava.util.List;@RestController @requestmapping ("User") Public classUsercontroller { @Reference PrivateUserService UserService; @RequestMapping ("Index")     PublicList<user>index () {List<User> all =Userservice.getall (); System.out.println ("Client reads to data:" +All ); returnAll ; }}

Here, you can see, is no longer using Autowire, but using reference annotations, is Dubbo inside.

3. Note:

Here's one thing to be aware of, the class of transmission, which must implementSerializable 接口, 表示支持序列化, 否则会报错的.

Results show:

From the browser, it does have access to the data. Look again, the background can print the information I want.

Look again at the Registration Monitoring center:

Look at the provider:

Consumers:

  

Springboot Multi-module--Splitting the web out-flow computing architecture

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.