0

I am getting below error while accessing http://localhost:8080/test_jboss_local/welcome url from browser :

No mapping found for HTTP request with URI [/test_jboss_local/welcome] in DispatcherServlet with name 'appServlet'

Below are the files:

web.xml :

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
        /WEB-INF/spring/root-context.xml
    </param-value>
    </context-param>

    <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/spring/appServlet/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>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

servlet-context.xml :

    <annotation-driven />
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>

root-context.xml :

<bean id="transactionManager"
        class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
     <tx:annotation-driven transaction-manager="transactionManager"/>
        <context:component-scan base-package="com.abc" />


    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <!-- <property name="dataSource" ref="dataSource" /> -->
        <property name="configLocation">
            <value>classpath:hibernate.cfg.xml</value>
        </property>
</bean>

HelloController.java :

@Controller
public class HelloController {

    @RequestMapping(value="/welcome", method = RequestMethod.GET)
    public String welcome(ModelMap model) {

        model.addAttribute("message", "Maven Web Project + Spring 3 MVC - welcome()");

        //Spring uses InternalResourceViewResolver and return back index.jsp
        return "index";

    }

    @RequestMapping(value="/welcome/{name}", method = RequestMethod.GET)
    public String welcomeName(@PathVariable String name, ModelMap model) {

        model.addAttribute("message", "Maven Web Project + Spring 3 MVC - " + name);
        return "index";

    }

index.jsp :

<html>
<body>
<h2>Hello World!</h2>

<h4>Message : ${message}</h1>   
</body>
</html>

I have check on net and i am not able to identify mistake. Please help.

VJS
  • 2,891
  • 7
  • 38
  • 70

3 Answers3

0

Changes Servlet mapping to this:

       <servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>
paul
  • 12,873
  • 23
  • 91
  • 153
0

Try adding this line to your servlet-context.xml configuration file:

<mvc:default-servlet-handler/>
Chaitanya
  • 15,403
  • 35
  • 96
  • 137
0

If your controller isn't in the default package then add

<context:annotation-config /> 
<context:component-scan base-package="your-controller's package" /> 

in spring-context.xml

jsjunkie
  • 559
  • 3
  • 7