search
HomeJavajavaTutorialHow to build Dubbo project with SpringBoot to implement the nth term of Fibonacci

    step1 Create a new project

    Method 1: Create a new project directly in IDEA as shown:

    How to build Dubbo project with SpringBoot to implement the nth term of Fibonacci

    Method 2: Create a new

    How to build Dubbo project with SpringBoot to implement the nth term of Fibonacci

    in start.spring.io. Some children may have discovered that the Server URL of the first method is the second website, which is the same.

    To create two new projects, the first project is as shown in the picture above, and the second project only needs to change the provider to consumer

    The rest remains unchanged, open it through IDEA after decompression

    step2 Create the required packages, interfaces and implementation classes

    provider project structure:

    How to build Dubbo project with SpringBoot to implement the nth term of Fibonacci

    consumer project structure:

    How to build Dubbo project with SpringBoot to implement the nth term of Fibonacci

    Please note that the locations of the two ServiceAPIs in the project, or the package names, must be strictly consistent, otherwise problems will occur later

    If they are inconsistent, you can press them as needed as follows Make changes

    How to build Dubbo project with SpringBoot to implement the nth term of Fibonacci

    xsd and place it in the specified directory:

    C:\Users\username\.lemminx\cache\http\code. alibabatech.com\schema\dubbo

    File:dubbo.xsd

    #step3 Create a new configuration file under the resources of the two projects

    The name that needs to be created is: spring-dubbo.xml

    In the configuration file of provider, write:

    <?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:dubbo="http://code.alibabatech.com/schema/dubbo"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    	   http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
        <!-- dubbo应用名称 -->
        <dubbo:application name="springboot-buddo-provider"/>
        <!-- 发布者 dubbo协议  -->
        <dubbo:protocol name="dubbo" port="20881"/>
        <!-- 定义bean -->
        <bean id="providerImpl" class="com.springdubbo.demo.springbootdubbo.apiImpl.ProviderImpl"/>
        <!-- dubbo服务 发布者发布服务  需要暴露的服务接口 -->
        <dubbo:service interface="com.springdubbo.demo.springbootdubbo.ServiceAPI" ref="providerImpl"
                       registry="N/A"/>
    </beans>

    In the configuration file of consumer, write:

    <?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:dubbo="http://code.alibabatech.com/schema/dubbo"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    	   http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
        <!-- dubbo应用名称 -->
        <dubbo:application name="springboot-buddo-consumer"/>
        <!-- 远程服务调用代理 -->
        <dubbo:reference id="consumerImpl"
                         interface="com.springdubbo.demo.springbootdubbo.ServiceAPI"
                         url="dubbo://localhost:20881" />
    </beans>

    step4 Code writing

    Import dependencies

    Add dependencies under the pom.xml of both projects:

    <dependency>
    	<groupId>com.alibaba.spring.boot</groupId>
    	<artifactId>dubbo-spring-boot-starter</artifactId>
    	<version>2.0.0</version>
    </dependency>

    provider

    ProviderImpl

    Don’t forget to add the Service annotation, and it must be dubbo’s Service

    package com.springdubbo.demo.springbootdubbo.apiImpl;
    import com.alibaba.dubbo.config.annotation.Service;
    import com.springdubbo.demo.springbootdubbo.ServiceAPI;
    /**
     * @author wuyt
     * @data 2022/6/11
     * @apiNote
     */
    @Service
    public class ProviderImpl implements ServiceAPI {
        public String getMessage(String message) {
            return "springboot-dubbo-provider  =>>>>>" + message;
        }
        public String getTheFeibN(int n) {
            //斐波那契数列第n项的实现逻辑
        }
    }

    ServiceAPI

    package com.springdubbo.demo.springbootdubbo;
    /**
     * @author wuyt
     * @data 2022/6/11
     * @apiNote
     */
    public interface ServiceAPI {
        public String getMessage(String message);
        public String getTheFeibN(int n);
    }

    SpringbootDubboApplication

    Be sure to add the ImportResource annotation

    package com.springdubbo.demo.springbootdubbo;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.context.annotation.ImportResource;
    @SpringBootApplication
    @ImportResource("classpath:spring-dubbo.xml")
    public class SpringbootDubboApplication {
        public static void main(String[] args) {
            SpringApplication.run(SpringbootDubboApplication.class, args);
        }
    }

    consumer

    ServiceAPI

    package com.springdubbo.demo.springbootdubbo;
    /**
     * @author wuyt
     * @data 2022/6/11
     * @apiNote
     */
    public interface ServiceAPI {
        public String getMessage(String message);
        public String getTheFeibN(int n);
    }

    SpringbootDubboApplication

    package com.springdubbo.demo.springbootdubbo;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.context.ConfigurableApplicationContext;
    import org.springframework.context.annotation.ImportResource;
    @SpringBootApplication
    @ImportResource("classpath:spring-dubbo.xml")
    public class SpringbootDubboApplication {
    	public static void main(String[] args) {
    		ConfigurableApplicationContext count = SpringApplication.run(SpringbootDubboApplication.class, args);
    		ServiceAPI impl = (ServiceAPI)count.getBean("consumerImpl");
    //		System.out.println(impl.getMessage("Hello dubbo"));
    		System.out.println(impl.getTheFeibN(10));
    	}
    }

    Port conflict change

    You can modify the port number of either provider or consumer

    Modify the port number of the consumer running here:

    How to build Dubbo project with SpringBoot to implement the nth term of Fibonacci

    step5 Run

    First run the provider, then run the consumer

    Result:

    How to build Dubbo project with SpringBoot to implement the nth term of Fibonacci

    The above is the detailed content of How to build Dubbo project with SpringBoot to implement the nth term of Fibonacci. For more information, please follow other related articles on the PHP Chinese website!

    Statement
    This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    AI Hentai Generator

    AI Hentai Generator

    Generate AI Hentai for free.

    Hot Article

    R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
    1 months agoBy尊渡假赌尊渡假赌尊渡假赌
    R.E.P.O. Best Graphic Settings
    1 months agoBy尊渡假赌尊渡假赌尊渡假赌
    Will R.E.P.O. Have Crossplay?
    1 months agoBy尊渡假赌尊渡假赌尊渡假赌

    Hot Tools

    DVWA

    DVWA

    Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

    PhpStorm Mac version

    PhpStorm Mac version

    The latest (2018.2.1) professional PHP integrated development tool

    SublimeText3 English version

    SublimeText3 English version

    Recommended: Win version, supports code prompts!

    SecLists

    SecLists

    SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

    ZendStudio 13.5.1 Mac

    ZendStudio 13.5.1 Mac

    Powerful PHP integrated development environment