2012-09-10 51 views
1

當我在JBoss上啓動項目時出現錯誤No mapping found for HTTP request with URI [/myappname/] in DispatcherServlet with name 'appServlet'。解決此處描述的另一個問題後發生此問題:"No Session found for current thread" after changing access method to the session在名爲'appServlet'的DispatcherServlet中使用URI [/ myappname /]發現HTTP請求沒有映射

在一切工作正常之前。我正在使用Apache Tiles 2.我正在閱讀幾個類似的問題,但找不到工作解決方案。

這是我DispatcherServlet Context文件,而無需Hibernate配置:

<?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"; 
    } 
} 

什麼是錯的我配置在這個時候?

回答

10

我認爲您的文件丟失<mvc:annotation-driven/>需要讀取@Controller@RequestMapping註釋。你可以閱讀更多關於這個herehere

+0

Thnx!這是我錯過的! –

+0

感謝您爲我的監督提供了簡單而正確的解決方案。 – paiego

0

的搜索解決方案是保持在DispatcherServlet Context文件都annotation-driven標籤喜歡這裏:

<annotation-driven /> 
<tx:annotation-driven /> 

我還沒有發現類似的解決方案,所以我gooing離開這裏吧。

0

有這種在春天servlet.xml文件

xmlns:mvc="http://www.springframework.org/schema/mvc 
xmlns:tx="http://www.springframework.org/schema/tx" 

http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd 

<mvc:annotation-driven /> 
<tx:annotation-driven /> 

在你的控制器類,使用

@Controller 
public class IndexController {..} 

它的工作原理!

0

我面臨着同樣的例外,並試圖解決上述所有問題,但沒有任何幫助 但我確實得到了一個指針問題是因爲該類不是在目標類文件夾中生成的,而且是由於不正確的Maven Project Structure導致Java控制器類沒有編譯。

檢查你是否有下面的結構,然後如果在target->class文件夾中生成類,那麼只能嘗試以上建議。

Project 
    src 
    main 
     java 
     resources 
    test 
     java 
     resources 
相關問題