ooooo-youwillsee commented on issue #9116:
URL: https://github.com/apache/dubbo/issues/9116#issuecomment-955621027


   The following is my code
   
   ```
   @Slf4j
   @SpringBootApplication
   public class DubboConsumerApplication {
   
        @DubboReference
        private UserService userService;
   
        public static void main(String[] args) {
                SpringApplication.run(DubboConsumerApplication.class, args);
        }
   
        @Bean
        public ApplicationRunner testApplicationRunner() {
                return __ -> {
                        String username = userService.getUsernameById(1L);
                        log.info("username: {}", username);
                };
        }
   }
   ``` 
   
   ```
   @SpringBootTest
   class DubboConsumerApplicationTest {
   
        @MockBean
        private UserService userService;
   
        @Test
        public void testDubboReferenceMockBean() {
                when(userService.getUsernameById(any())).thenReturn("mock 
username");
   
                String username1 = userService.getUsernameById(1L);
                assertEquals("mock username", username1);
   
                String username2 = userService.getUsernameById(1L);
                assertEquals("mock username", username2);
        }
   }
   ```
   
   bootstrap.yml
   
   ```
   spring:
     application:
       name: demo-spring-cloud-dubbo-consumer
   dubbo:
     protocols:
       dubbo:
         name: dubbo
         port: -1
     registry:
       address: N/A
   #    address: 224.5.6.7:2222  # No matter what is configured, the error is 
reported
     scan:
       base-packages: com.ooooo
     consumer:
       check: false
   ```
   
   dependencies
   
   ```
   mavenBom "com.alibaba.cloud:spring-cloud-alibaba-dependencies:2.2.6.RELEASE"
   mavenBom "org.springframework.cloud:spring-cloud-dependencies:Hoxton.SR10"
   //=========
       api('org.springframework.boot:spring-boot-starter-web')
       api('com.alibaba.cloud:spring-cloud-starter-dubbo')
       api('com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-discovery')
   ```
   
   
   You can find the code 
[here](https://github.com/ooooo-youwillsee/java-framework-guide/tree/main/spring-cloud-examples/spring-cloud-dubbo/spring-cloud-dubbo-consumer)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to