I know it's not a best practice to make a controller transactional but want to try the solution discussed here
According to the Spring MVC documentation 17.3.2:
A common pitfall when working with annotated controller classes happens when applying functionality that requires creating a proxy for the controller object (e.g. @Transactional methods). Usually you will introduce an interface for the controller in order to use JDK dynamic proxies. To make this work you must move the @RequestMapping annotations, as well as any other type and method-level annotations (e.g. @ModelAttribute, @InitBinder) to the interface as well as the mapping mechanism can only "see" the interface exposed by the proxy.
I should be able to make a RestController method transactional if I "move all method annotations to its interface"?
Under this assumption, I wrote following codes, which still didn't give me a transactional doSth() method:
public interface SomeController{
@Transactional
@RequestMapping(...)
void doSth()
}
@RestController
public class SomeControllerImpl implements SomeController{
@Override
public void doSth(){...}
}
web.xml
<servlet>
<servlet-name>someServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>...</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>someServlet</servlet-name>
<url-pattern>...</url-pattern>
</servlet-mapping>
context.spring.xml
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/project" resource-ref="true" />
<tx:annotation-driven />
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager" />
Could someone help explain why this doesn't work and is there a way to make a method in RestController transactional?