Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@Transaction makes my REST Endpoints disappear

tl;dr

  • Have a @RestController implementing an Interface
  • Everything works fine
  • added @Transactional
  • REST endpoints are not being registered any longer until I completely remove the Interface

Long 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"?!

like image 628
Olli Avatar asked Dec 06 '25 03:12

Olli


1 Answers

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.

like image 159
user3510149 Avatar answered Dec 07 '25 17:12

user3510149