tl;dr
@RestController implementing an Interface@TransactionalLong story:
I'm using Spring Boot with Spring MVC to deliver RESTful Webservices. I had a @RestController class implementing an Interface which had all the @RequestMapping Annotations to have a better overview about what Endpoints are there and mapped to which Controller Methods.
@RestController
public class UserController extends AbstractController implements IUserController {
...
}
@RequestMapping("/blub/user/")
public interface IUserController {
@RequestMapping(value = "showEditUser/{id}", method = { RequestMethod.GET })
public ShowEditUserResponse showEditUser(final Long userId);
...
}
Everything was working fine. On Startup I got a bunch of log messages like:
Mapped "{[/blub/user/updateUser],methods=[PUT]}" onto public org.blub.core.rest.model.user.UpdateUserResponse org.blub.server.controller.impl.UserController.updateUser(org.blub.core.rest.model.user.UpdateUserRequest)
Then I added @Transactional to the Implementation of the Controller (also tried the Interface). Now the logmessage changed:
Mapped "{[/blub/user/updateUser],methods=[PUT]}" onto public org.blub.core.rest.model.user.UpdateUserResponse org.blub.server.controller.IUserController.updateUser(org.blub.core.rest.model.user.UpdateUserRequest)
Please notice, that the message change frpm impl.UserController to IUserController which results in a 404 HTTP Status when calling the URI.
When I move all @RequestMapping annotations to the Implementation and remove the whole Interface, everything works as expected.
Why is having an Interface causing this kind of trouble? I thought that especially when it comes to AOP based proxying, Interface is a "must have"?!
I had the same problem and my project also use javamelody, whitch is a monitoring library working with proxy.
After disabling it, my rest endpoint went back to life. So the problem is probably linked with some proxy interference between spring mvc and a proxy library.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With