Pre-check

  • [x] I am sure that all the content I provide is in English.

Search before asking

  • [x] I had searched in the issues and found no similar issues.

Apache Dubbo Component

Java SDK (apache/dubbo)

Dubbo Version

Dubbo java 3.3.4 , jdk 8 , macos

Steps to reproduce this issue

I defined the service using triple-rest SpringMVC, and I had an error simulating rpc call injection

@RequestMapping("/test")
public interface TestService {

    @GetMapping(value = "/sayHello")
    String sayHello(@RequestParam(name = "name") String name);

    @PostMapping(value = "/sayHello2")
    String sayHello2(@RequestBody TestVO testVO);
}
@DubboService
public class TestServiceImpl implements TestService{
    @Override
    public String sayHello(String name) {
        return "hello " + name;
    }

    @Override
    public String sayHello2(TestVO testVO) {
        return testVO.toString();
    }
}
@RequestMapping("/serviceA")
public interface ServiceA {

    @GetMapping("/test")
    void test();
}
@DubboService
public class ServiceAImpl implements ServiceA{

    @DubboReference(scope = "remote")
    private TestService testService;

    @Override
    public void test() {
        System.out.println(testService.sayHello("service A"));
    }
}

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'testService' method 
org.example.dubbodemo.service.TestService#sayHello2(TestVO)
to {POST [/test/sayHello2]}: There is already 'testServiceImpl' bean method
org.example.dubbodemo.service.TestServiceImpl#sayHello2(TestVO) mapped.

What you expected to happen

It should start normally

Anything else

No response

Are you willing to submit a pull request to fix on your own?

  • [x] Yes I am willing to submit a pull request on my own!

Code of Conduct

Comment From: Stellar1999

I can't reproduce your problem. Can you upload your project?

Comment From: zhilaohu32

dubbo-demo.zip

I can't reproduce your problem. Can you upload your project?

Comment From: Stellar1999

I think removing spring-boot-starter-web and replacing it with spring-web can solve your problem.

dubbo-demo.zip

I can't reproduce your problem. Can you upload your project?

Comment From: zhilaohu32

spring-boot-starter-web

Why an error occurs when spring-boot-starter-web is used? Will the problem be fixed?

Comment From: Stellar1999

spring-boot-starter-web

Why an error occurs when spring-boot-starter-web is used? Will the problem be fixed?

They both execute SpringMVC RequestMappingHandlerMapping. I don't think it's a Dubbo bug. We can consider optimizing it, but only as an optimization.

Comment From: zhilaohu32

spring-boot-starter-web

Why an error occurs when spring-boot-starter-web is used? Will the problem be fixed?

They both execute SpringMVC RequestMappingHandlerMapping. I don't think it's a Dubbo bug. We can consider optimizing it, but only as an optimization.

I want it to be optimized. We need it.

Comment From: Stellar1999

spring-boot-starter-web

Why an error occurs when spring-boot-starter-web is used? Will the problem be fixed?

They both execute SpringMVC RequestMappingHandlerMapping. I don't think it's a Dubbo bug. We can consider optimizing it, but only as an optimization.

I want it to be optimized. We need it.

After communicating with others in the community, I realized that my previous explanation was incorrect, and I sincerely apologize for the misunderstanding.

In fact, this error occurs because the @RequestMapping annotation is parsed by Spring's RequestMappingHandlerMapping, which causes both testServiceImpl and testService beans to be detected as duplicates.

A better solution is to remove the @RequestMapping annotation from the class.

Comment From: zhilaohu32

remove the @RequestMapping annotation from the class.

remove the @RequestMapping annotation from the class.

Unable to start after removing the @RequestMapping annotation from the class

Comment From: Stellar1999

remove the @RequestMapping annotation from the class.

remove the @RequestMapping annotation from the class.

Unable to start after removing the @RequestMapping annotation from the class

remove TestService @RequestMapping

Comment From: zhilaohu32

remove the @RequestMapping annotation from the class.

remove the @RequestMapping annotation from the class. Unable to start after removing the @RequestMapping annotation from the class

remove TestService @RequestMapping

I'm sure I've removed it, but it's still an error.

@RestController
public interface TestService {

    @GetMapping(value = "/test/sayHello")
    String sayHello(@RequestParam(name = "name") String name);

    @PostMapping(value = "/test/sayHello2")
    String sayHello2(@RequestBody TestVO testVO);
}

Comment From: Stellar1999

remove the @RequestMapping annotation from the class.

remove the @RequestMapping annotation from the class. Unable to start after removing the @RequestMapping annotation from the class

remove TestService @RequestMapping

I'm sure I've removed it, but it's still an error.

@RestController public interface TestService {

@GetMapping(value = "/test/sayHello")
String sayHello(@RequestParam(name = "name") String name);

@PostMapping(value = "/test/sayHello2")
String sayHello2(@RequestBody TestVO testVO);

}

I’m sorry.and remove @restcontroller

Comment From: zhilaohu32

remove the @RequestMapping annotation from the class.

remove the @RequestMapping annotation from the class. Unable to start after removing the @RequestMapping annotation from the class

remove TestService @RequestMapping

I'm sure I've removed it, but it's still an error. @RestController public interface TestService { ``` @GetMapping(value = "/test/sayHello") String sayHello(@RequestParam(name = "name") String name);

@PostMapping(value = "/test/sayHello2") String sayHello2(@RequestBody TestVO testVO); ```

}

I’m sorry.and remove @RestController

A new error has occurred

org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'; nested exception is java.lang.reflect.UndeclaredThrowableException

Comment From: Stellar1999

remove the @RequestMapping annotation from the class.

remove the @RequestMapping annotation from the class. Unable to start after removing the @RequestMapping annotation from the class

remove TestService @RequestMapping

I'm sure I've removed it, but it's still an error. @RestController public interface TestService { ``` @GetMapping(value = "/test/sayHello") String sayHello(@RequestParam(name = "name") String name);

@PostMapping(value = "/test/sayHello2") String sayHello2(@RequestBody TestVO testVO); ```

}

I’m sorry.and remove @RestController

A new error has occurred

org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'; nested exception is java.lang.reflect.UndeclaredThrowableException

This looks like a Spring Boot error. In fact, after removing all @RequestMapping and @RestController, it runs normally on my MacBook.

Comment From: zhilaohu32

remove the @RequestMapping annotation from the class.

remove the @RequestMapping annotation from the class. Unable to start after removing the @RequestMapping annotation from the class

remove TestService @RequestMapping

I'm sure I've removed it, but it's still an error. @RestController public interface TestService { ``` @GetMapping(value = "/test/sayHello") String sayHello(@RequestParam(name = "name") String name);

@PostMapping(value = "/test/sayHello2") String sayHello2(@RequestBody TestVO testVO); ```

}

I’m sorry.and remove @RestController

A new error has occurred org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'; nested exception is java.lang.reflect.UndeclaredThrowableException

This looks like a Spring Boot error. In fact, after removing all @RequestMapping and @RestController, it runs normally on my MacBook.

ok,Will the problem be optimized? Make @ReqeustMapping and @RestController tagable?