在DispatcherServlet中找不到具有URI [/ myappname /]的HTTP请求的映射,名称为“appServlet” [英] No mapping found for HTTP request with URI [/myappname/] in DispatcherServlet with name 'appServlet'

查看:170
本文介绍了在DispatcherServlet中找不到具有URI [/ myappname /]的HTTP请求的映射,名称为“appServlet”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有错误当我在JBoss上启动项目时,在DispatcherServlet中找不到名为'appServlet'的。在解决此处描述的另一个问题后出现此问题:找不到当前线程的会话更改会话的访问方法后

I have got error No mapping found for HTTP request with URI [/myappname/] in DispatcherServlet with name 'appServlet' when I was starting my project on JBoss. This is issue has occurred after resolving another issue described here: "No Session found for current thread" after changing access method to the session

在一切正常之前。我正在使用Apache Tiles 2.我正在阅读几个类似的问题,但我找不到可行的解决方案。

Before everything was working fine. I am using Apache Tiles 2. I am reading few similar questions but I can't find working solution.

这是我的 DispatcherServlet上下文文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
         xmlns:tx="http://www.springframework.org/schema/tx"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:beans="http://www.springframework.org/schema/beans"
         xmlns:context="http://www.springframework.org/schema/context"
         xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-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/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

<!-- Enables the Spring MVC @Controller programming model -->
<tx:annotation-driven />
<context:annotation-config />
<context:component-scan base-package="finances.webapp" />

<!-- Handles HTTP GET requests for resources by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />

<beans:bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    <beans:property name="definitions">
        <beans:list>
            <beans:value>/WEB-INF/tiles-definitions.xml</beans:value>
        </beans:list>
    </beans:property>
</beans:bean>

<beans:bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <beans:property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView" />
</beans:bean>

我的 web.xml 整个文件:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">

<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/spring/root-context.xml
    </param-value>
</context-param>

<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<listener>
    <listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</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/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>

</web-app>

这是我的 IndexController

@Controller
public class IndexController {

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String index(Model model, Principal principal) {
        return "index";
    }
}

此时我的配置有什么问题?

What is wrong with my configuration at this moment?

推荐答案

我认为你遗失了< mvc:annotation-driven /> 需要读取 @Controller @RequestMapping 注释。您可以在此处在其他地方

I think your are missing <mvc:annotation-driven/> which is required to read the @Controller and @RequestMapping annotations. You can read more on this here and here.

这篇关于在DispatcherServlet中找不到具有URI [/ myappname /]的HTTP请求的映射,名称为“appServlet”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆