No adapter for handler in Spring MVC

I have a problem with a simple spring mvc controller written in scala:

@Controller class HelloWorldController { implicit def sessionFactory2Session(sf: SessionFactory) = sf.getCurrentSes @Autowired var sessionFactory: SessionFactory = null @Transactional @RequestMapping(value=Array("/hello.html"),method = Array(RequestMethod.GET,RequestMethod.POST)) def showHello = { val document = new CustomDocument("name","custom") sessionFactory.save(document) sessionFactory.flush "helloPage" } } 

When I tried to access /hello.html, I got an exception:

 javax.servlet.ServletException: No adapter for handler: Does your handler implement a supported interface like Controller? at org.springframework.web.servlet.DispatcherServlet.getHandlerAdapter(DispatcherServlet.java:951) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:758) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:717) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549) 

But when I deleted the @Transactional annotation - everything works !!. spring can't find query matching with two annotations? My fragment of applicationContext.xml:

  <bean id="openSessionInViewInterceptor" class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor"> <property name="sessionFactory" ref="sessionFactory"/> </bean> <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"> <property name="interceptors"> <list><ref bean="openSessionInViewInterceptor"/></list> </property> <property name="alwaysUseFullPath" value="true" /> </bean> <context:component-scan base-package="scala.hibernate"/> <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/WEB-INF/jsp/"/> <property name="suffix" value=".jsp"/> </bean> <!-- for transaction --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManaager"> <property name="sessionFactory" ref="sessionFactory"/> <property name="dataSource" ref="dataSource"/> </bean> <tx:annotation-driven/> 

EDIT

The transactional aspect is applied using a dynamic proxy and prevents access to spring MVC MVC for @RequestMapping annotations in the target class Solution:

  <tx:annotation-driven proxy-target-class="true"/> 
+4
source share
2 answers

Try adding <context:annotation-config /> to your applicationContext.xml and see if this fixes the problem.

0
source

declare the next bean. this should solve the problem

 <bean id="simpleHandler" class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/> 

will update you as soon as it finds out the root cause.

-1
source

All Articles