java - Inherited controller method without type parameter does not get mapped with RequestMapping -


i created base spring controller latest web app project inherit basic crud controllers, called crudcontroller:

class crudcontroller<t, k extends serializable> 

t entity type, , k key used type (pretty parameters needed spring's crudrepository). create rest controller extending it, so:

@restcontroller @requestmapping(path = "/hats") public class hatcontroller extends crudcontroller<hat, integer> { } 

everything works great, except method gets list of items, /hats. method, 405 method not allowed. when @ logging done during startup, can see requestmappinghandlermapping did not map {[/hats],methods=[get]} did map other 4 methods in controller. here code method isn't being mapped:

@requestmapping(method = requestmethod.get) public httpentity<?> getall() {     iterable<t> result = controllerrepository.findall();     return new responseentity<object>(result, httpstatus.ok); } 

after experimentation, have discovered if add parameter getall method 1 of class parameter types, method mapped. check similar code out:

@requestmapping(method = requestmethod.get) public httpentity<?> getall(k dontuse) {     iterable<t> result = controllerrepository.findall();     return new responseentity<object>(result, httpstatus.ok); } 

with small code change, /find call works fine. can keep dummy parameter in there , work, smells.

any ideas? simplified project replicates issue can found here:

simple project

there's bug in java, see bug reports here , here, class#getdeclaredmethods() returns bridge method each inherited method superclass declared package-private. based on javadoc, shouldn't that.

this confuses spring mvc's inspection of @controller annotated classes , handler methods. going detail in answer won't useful, can @ code handles here.

the simplest solution declare crudrepository class public.

public class crudcontroller<t, k extends serializable>  

Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -