开发者

No adapter for handler in Spring MVC

开发者 https://www.devze.com 2023-01-12 09:05 出处:网络
I have problem with simple spring mvc controller written in scala: @Controller class HelloWorldController {

I have problem with 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 received 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.spr开发者_如何学Goingframework.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 removed @Transactional annotation - everything works!!. Spring can't find request mapping with two annotations? My applicationContext.xml fragment:

 <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

Transactional aspect is applied using dynamic proxy, and it prevents Spring MVC from accessing the @RequestMapping annotations on the target class Solution:

    <tx:annotation-driven proxy-target-class="true"/>


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


declare following bean . this should solve the problem

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

will update you once find out the root cause..

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号