Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Cannot have an @RequestMapping and @FrameworkMapping mapped to the same endpoint with different HTTP methods

Abierto
#4 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
java, spring
Área
api, backend

Línea de trabajo

Comienza rastreando DispatcherServlet a través de RequestMappingInfoHandlerMapping y FrameworkMappingHandlerMapping, usando el ejemplo de CartEndpoint y CustomCartEndpoint como reproducción. Identifica dónde la asignación GET impide la resolución posterior y, a continuación, verifica que las asignaciones GET y POST equivalentes puedan resolverse con ambas anotaciones sin el workaround descrito.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

The body of this issue was copied over from BroadleafCommerce/Issues#3.

Initially reported at https://stackoverflow.com/questions/45652009/broadleaf-apis-not-working

The example where this fails is CartEndpoint. We have an extension of the Broadleaf CartEndpoint called CustomCartEndpoint in DemoSite. The problem is that we overwrote the exact same URL that exists in the API module. So we essentially have this situation:

@FrameworkMapping(value = "/cart", method = RequestMethod.POST)
 public OrderWrapper createNewCartForCustomer(HttpServletRequest request) {
    ...
}

@RequestMapping(value = "/cart", method = RequestMethod.GET)
public OrderWrapper findCartForCustomer(HttpServletRequest request) {
    ...
}

The problem is when the DispatcherServlet goes looking for a HandlerMapping to resolve the current request, it first consults the default RequestMappingInfoHandlerMapping (which is where all of the @RequestMapping endpoints go). The RequestMappingInfoHandlerMapping essentially only looks for something that matches the URL string and results in a partial mapping for the findCartForCustomer() method (which is a GET). Thus, it throws a 405 method not allowed rather than continue to send the request downstream to be handled by FrameworkMappingHandlerMapping, which is where all of the @FrameworkMapping methods are.

The workaround is to in CustomCartEndpoint in DemoSite extend the createNewCartForCustomer() method, put @RequestMapping on it and just call super. Thus, the final CustomCartEndpoint will look like:

@RestController
@RequestMapping(value = "/cart",
                produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
public class CustomCartEndpoint extends CartEndpoint {

    @Override
    @RequestMapping(value = "", method = RequestMethod.GET)
    public OrderWrapper findCartForCustomer(HttpServletRequest request) {
        try {
            return super.findCartForCustomer(request);
        } catch (Exception e) {
            // if we failed to find the cart, create a new one
            return createNewCartForCustomer(request);
        }
    }
    
    @Override
    @RequestMapping(value = "", method = RequestMethod.POST)
    public OrderWrapper createNewCartForCustomer(HttpServletRequest request) {
        return super.createNewCartForCustomer(request);
    }
}
Lenguaje dominante
Java
Estrellas
2
Forks
2
Métricas de merge de PR
Sin PR fusionados en 30 d

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de BroadleafCommerce/spring-frameworkmapping

Todos los issues de BroadleafCommerce/spring-frameworkmapping

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.