question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

spring-boot: Using @Topic annotation reads the path from methods' @PostMapping, ignoring class-level @RequestMapping

See original GitHub issue

Expected Behavior

When annotating a controller with @RequestMapping and a method with @PostMapping actual HTTP path is the combination of both.

So, when annotating the method with @Topic I expect it to map the topic with the full path.

Actual Behavior

The topic is mapped with a truncated path, which is only the @PostMapping value. Publishing to the topic constantly fail, as path not found.

Steps to Reproduce the Problem

Create a controller and start the app:

@Controller
@RequestMapping(value = "/v1")
public class MyController {
    @Topic(pubsubName = "pubsub", name = "my-topic")
    @PostMapping("foo")
    public void foo(@RequestBody(required = false) CloudEvent<String> cloudEvent) {
        log.trace("{}", cloudEvent.getData());
    }
}

Publish with dapr publish --publish-app-id myapp --pubsub pubsub --topic my-topic --data hello-world.

Observe sidecar error: "non-retriable error returned from app while processing pub/sub event 9d8b9f70-9985-4665-8ce8-1d63a7935977: {\"timestamp\":1645712855614,\"status\":404,\"error\":\"Not Found\",\"message\":\"No message available\",\"path\":\"/foo\"}. status code returned: 404".

Error referrs to "path": "/foo", but actual path is /v1/foo.

The code that can be improved is on https://github.com/dapr/java-sdk/blob/master/sdk-springboot/src/main/java/io/dapr/springboot/DaprBeanPostProcessor.java

Release Note

RELEASE NOTE: FIX Topic annotation handles class-level @RequestMapping

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
artursouzacommented, Feb 24, 2022

Thanks for reporting this bug with such level of detail.

0reactions
ittayscommented, Mar 21, 2022

Well done! 🌟

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring Boot: How can I ignore class Mapping in Method ...
How can I ignore my in the class defined requestMapping in only one of my Methods? Code: @RestController @RequestMapping({"/api/user/"}) ...
Read more >
Using the Spring @RequestMapping Annotation
In this post, I show you how to use the Spring MVC ... The class-level annotation maps a specific request path or pattern...
Read more >
Web on Servlet Stack - Spring
The two main HandlerMapping implementations are RequestMappingHandlerMapping (which supports @RequestMapping annotated methods) and SimpleUrlHandlerMapping ( ...
Read more >
Spring @RequestMapping - Baeldung
In this tutorial, we'll focus on one of the main annotations in Spring MVC: @RequestMapping. Simply put, the annotation is used to map...
Read more >
Jackson JSON Request and Response Mapping in Spring Boot
Jackson JSON ObjectMapper · Convert the incoming JSON Request Body to Java Object of your method @RequestBody argument. Generally used in POST ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found