Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] triple-rest dependency injection failed #15274

Open
4 tasks done
zhilaohu32 opened this issue Mar 25, 2025 · 14 comments
Open
4 tasks done

[Bug] triple-rest dependency injection failed #15274

zhilaohu32 opened this issue Mar 25, 2025 · 14 comments
Labels
component/need-triage Need maintainers to triage type/need-triage Need maintainers to triage

Comments

@zhilaohu32
Copy link

zhilaohu32 commented Mar 25, 2025

Pre-check

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

Search before asking

  • 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?

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

Code of Conduct

@zhilaohu32 zhilaohu32 added component/need-triage Need maintainers to triage type/need-triage Need maintainers to triage labels Mar 25, 2025
@Stellar1999
Copy link
Contributor

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

@zhilaohu32
Copy link
Author

dubbo-demo.zip

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

@Stellar1999
Copy link
Contributor

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?

@zhilaohu32
Copy link
Author

zhilaohu32 commented Mar 28, 2025

spring-boot-starter-web

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

@Stellar1999
Copy link
Contributor

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.

@zhilaohu32
Copy link
Author

zhilaohu32 commented Mar 28, 2025

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.

@Stellar1999
Copy link
Contributor

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.

@zhilaohu32
Copy link
Author

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

@Stellar1999
Copy link
Contributor

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

@zhilaohu32
Copy link
Author

zhilaohu32 commented Mar 28, 2025

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);
}

@Stellar1999
Copy link
Contributor

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

@zhilaohu32
Copy link
Author

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

@Stellar1999
Copy link
Contributor

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.

@zhilaohu32
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/need-triage Need maintainers to triage type/need-triage Need maintainers to triage
Projects
Status: Todo
Development

No branches or pull requests

2 participants