當我嘗試使用基於註解的控制器訪問我的頁面時,我總是從tomcat中獲得「請求的資源不可用」。基於註釋的彈簧映射不起作用。 404
控制器:
@Controller
public class HelloWorldController {
@RequestMapping("/hello")
public ModelAndView helloWorld() {
String message = "Hello World, Spring 3.0!";
return new ModelAndView("hello", "message", message);
}
}
我嘗試訪問/hello.htm並獲得404 mainpage.htm工作正常,但它的控制器不是註釋類型。
dipsatcher-servlet.xml中:
<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:/blog.properties"/>
<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/>
<mvc:resources mapping="/resources/**" location="/resources/" />
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
<context:component-scan base-package="com.mycomp.controller" />
<!--ViewResolver määrab kontrollerklassist tagastatud parameetri järgi vaate. Hetkel jsp lehekülg -->
<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>
<bean name="/mainpage.htm" class="com.mycomp.controller.MainPage">
<property name="message" value="${message}"/>
<property name="maxposts" value="${maxposts}"/>
</bean>
你有沒有在web.xml中DispatcherServlet的設置? – gkamal 2011-12-25 16:30:49