Hi all, I'm new to Spring Framework and using Spring for my current web project.
I would like to ask, is <mvc:annotation-driven/> needed when we use @Controller and @RequestMapping annotation ?
Because if I delete those line from my context-config.xml, I got this error message:
And the Apache log shows this message:Code:HTTP Status 404 - The requested resource () is not available.
I'm really confused because many references out thereCode:05:38:48,021 WARN "http-bio-8084"-exec-11 servlet.PageNotFound:1057 - No mapping found for HTTP request with URI [/Edunesia/Beranda] in DispatcherServlet with name 'SpringDispatcherServlet'
say that <mvc:annotation-driven/> is only needed if we want to use certain feature, such as Jackson for JSON.
Here is my web.xml:
context-config.xmlCode:<?xml version="1.0" encoding="UTF-8"?> <web-app metadata-complete="true" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <servlet> <servlet-name>SpringDispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/context-config.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>SpringDispatcherServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <session-config> <session-timeout> 30 </session-timeout> </session-config> </web-app>
The controller which has the problem:Code:<?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:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd"> <context:component-scan base-package="net.edunesia.controller"/> <mvc:view-controller path="/" view-name="welcome"/> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/views/"/> <property name="suffix" value=".jsp"/> </bean> </beans>
I don't create /WEB-INF/SpringDispatcherServlet.xmlCode:package net.edunesia.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @Controller @RequestMapping("/Beranda") public class Beranda { @RequestMapping(method = RequestMethod.GET) public String get() { return "beranda"; } }
because I set /WEB-INF/spring/context-config.xml for contextConfigLocation
as DispatcherServlet init parameter.
Thank you.


Reply With Quote