java - Spring Error - Handler Method not Found -
i have problem in calling controller. server returns did not find handler method error. following web.xml :
<?xml version="1.0" encoding="utf-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5" 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_2_5.xsd"> <welcome-file-list> <welcome-file>login.jsp</welcome-file> </welcome-file-list> <context-param> <param-name>contextconfiglocation</param-name> <param-value>/web-inf/classes/root-context.xml</param-value> </context-param> <context-param> <param-name>log4jconfiglocation</param-name> <param-value>/web-inf/classes/log4j.xml</param-value> </context-param> <context-param> <param-name>log4jrefreshinterval</param-name> <param-value>1000</param-value><!-- 10000 --> </context-param> <!-- creates spring container shared servlets , filters --> <filter> <filter-name>encodingfilter</filter-name> <filter-class>org.springframework.web.filter.characterencodingfilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>utf-8</param-value> </init-param> <init-param> <param-name>forceencoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingfilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class>org.springframework.web.context.contextloaderlistener</listener-class> </listener> <!-- processes application requests --> <servlet> <servlet-name>appservlet</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <init-param> <param-name>contextconfiglocation</param-name> <param-value>/web-inf/classes/servlet-context.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>appservlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>
the following servlet-context.xml
<?xml version="1.0" encoding="utf-8"?> <beans:beans xmlns="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:task="http://www.springframework.org/schema/task" xmlns:util="http://www.springframework.org/schema/util" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemalocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd"> <!-- dispatcherservlet context: defines servlet's request-processing infrastructure --> <!-- enables spring mvc @controller programming model --> <mvc:annotation-driven /> <context:annotation-config /> <context:component-scan base-package="com.til.et" /> <default-servlet-handler /> <context:property-placeholder location="classpath:application.properties" /> <!-- handles http requests /resources/** efficiently serving static resources in ${webapproot}/resources directory --> <resources mapping="/resources/**" location="/resources/" /> <!-- resolves views selected rendering @controllers .jsp resources in /web-inf/rest/jsp directory --> <beans:bean class="org.springframework.web.servlet.view.internalresourceviewresolver"> <beans:property name="viewclass" value="org.springframework.web.servlet.view.jstlview" /> <beans:property name="prefix" value="/web-inf/rest/jsp/" /> <beans:property name="suffix" value=".jsp" /> </beans:bean> <!-- configure plugin json request , response in method handler --> <beans:bean class="org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter"> <beans:property name="messageconverters"> <beans:list> <beans:ref bean="jsonmessageconverter" /> </beans:list> </beans:property> </beans:bean> <!-- configure bean convert json pojo , vice versa --> <beans:bean id="jsonmessageconverter" class="org.springframework.http.converter.json.mappingjackson2httpmessageconverter"> </beans:bean> </beans:beans>
and following controller
package com.et.til.mynewsletters.admin.controller; import javax.servlet.http.httpservletrequest; import org.springframework.stereotype.controller; import org.springframework.ui.model; import org.springframework.ui.modelmap; import org.springframework.validation.bindingresult; import org.springframework.validation.annotation.validated; import org.springframework.web.bind.annotation.modelattribute; import org.springframework.web.bind.annotation.requestmapping; import org.springframework.web.bind.annotation.requestmethod; import org.springframework.web.bind.annotation.responsebody; @controller public class logincontroller { @requestmapping(value = "/hello", method = requestmethod.get) @responsebody public string hello(httpservletrequest request) { return "hello"; } }
the /hello mapping not working inspite of url pattern in dispatcher servlet being "/". tomcat server returns handler method not found , there no error or exception in tomcat logs. please me out.
can try correcting <context:component-scan base-package="com.til.et" />
<context:component-scan base-package="com.te.til" />
?
Comments
Post a Comment