2011-04-14 6 views
1

이것은 사소한 일일 수 있습니다. 하지만 이것에 대한 정보는 얻지 못했습니다.Annotation을 사용하고 컨트롤러를 구현하는 스프링 MVC 컨트롤러 구현

Controller 인터페이스를 구현하거나 AbstractController를 확장하는 Controller 구현 클래스를 동일한 웹 애플리케이션에서 사용할 수 있습니까?

그렇다면 어떻게해야할까요?

나는 다음과 같은 스프링 컨텍스트를 작성했지만, 컨트롤러를 구현하는 클래스는 HomePageController가로드되지 않습니다 내 경우에는
<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:lang="http://www.springframework.org/schema/lang" 
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd 
     http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd 
     http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> 



    <bean name="/home.htm" class="com.dell.library.web.HomePageController"> 
     <property name="library" ref="library" /> 
    </bean> 

    <context:component-scan base-package="com.dell.library.web.anot" /> 
    <mvc:annotation-driven /> 

    <bean id="viewResolver" 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="prefix"> 
      <value>/WEB-INF/jsp/</value> 
     </property> 
     <property name="suffix"> 
      <value>.jsp</value> 
     </property> 
    </bean> 

</beans> 

로드되지 않았습니다. 이것이 올바른 방법입니까?

감사 다누시

답변

3

<mvc:annotation-driven> 효과적으로 기존 컨트롤러를 사용하지 않습니다. 당신은

<bean class = "org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" /> 
<bean class = "org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" /> 

를 선언하여이를 활성화해야 UPDATE : DispatcherServlet 기능이 전략 클래스의 sevaral 종류에 의해 제어됩니다. 특히 HandlerMapping은 URL을 컨트롤러에 매핑하는 방법을 정의하고 HandlerAdapter은 특정 컨트롤러 호출을 수행하는 방법을 정의합니다.

위의 줄은 URL을 빈 이름에 매핑하고 Controller 클래스를 호출하는 전략을 선언합니다. 실제로 전략은 기본적으로 활성화되지만 다른 전략이 명시 적으로 선언되지 않은 경우에만 가능합니다. <mvc:annotation-driven>은 명시 적으로 자신의 전략을 선언하므로이 bean을 명시 적으로 선언해야합니다.

DispatcherServlet javadoc도 참조하십시오.

+0

감사합니다. 그것은 일했다. 이 두 항목은이 경우 무엇을합니까? –

+0

@ dhanush : 업데이트되었습니다. – axtavt

+0

내가 0 upvotes와 허용 대답을보고 싫어 :) – Bozho

관련 문제