2014-01-22 4 views
0

Привет Я работаю над Spring MVC 4.0. Когда я пытаюсь получить доступ к странице входа по URL-адресу http://localhost:8080/bookstore-web-0.0.1-SNAPSHOT/bookstore/authentication/login, он показывает ошибку 404. И журналы показывает ниже предупреждения404- PageNot Found in Spring MVC

WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/bookstore-web-0.0.1-SNAPSHOT/bookstore/authentication/login] in DispatcherServlet with name 'appServlet']] 

Здесь bookstore-web-0.0.1-SNAPSHOT мой .war файл. я следующее отображение в моей 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, /WEB-INF/spring/appServlet/security-config.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> 

<!-- 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> 

<filter> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <filter-class> 
     org.springframework.web.filter.DelegatingFilterProxy 
    </filter-class> 
</filter> 

<filter-mapping> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <url-pattern>/bookstore/*</url-pattern> 
    <dispatcher>REQUEST</dispatcher>  
    <dispatcher>FORWARD</dispatcher> 
</filter-mapping> 

<!-- Map all /resources requests to the Resource Servlet for handling --> 
<!-- <servlet-mapping> 
    <servlet-name>Resources Servlet</servlet-name> 
    <url-pattern>/resources/*</url-pattern> 
</servlet-mapping> --> 

<servlet-mapping> 
    <servlet-name>appServlet</servlet-name> 
    <url-pattern>/bookstore/*</url-pattern> 
</servlet-mapping> 

контроллер находится:

package com.abhendra.bookstore; 
@Controller 
public class AuthenticationController { 

private static final Logger logger = LoggerFactory.getLogger(AuthenticationController.class); 

/** 
* Simply selects the home view to render by returning its name. 
*/ 
@RequestMapping(value = "/authentication/login", method = RequestMethod.GET) 
public String home(Locale locale, Model model) { 
    logger.info("Welcome home! The client locale is {}.", locale); 


    System.out.println("In Controller!!!!!!!!!!!!!!!!!!!!!!"); 
    return "login"; 
} 

}

Я также сделал компонент сканирования запись в моем корневом контексте. xml-файл. например:

<context:component-scan base-package="com.abhendra.bookstore, com.abhendra.core" /> 
<context:annotation-config /> 

Я не понимаю, где я совершаю ошибку.

Спасибо заранее.

+0

книжного магазина веб-0.0.1-SNAPSHOT мой .war файл. –

+0

Давайте посмотрим вашу конфигурацию 'servlet-context.xml'. –

ответ

1

Это не достаточно, чтобы просто сканировать @Controller аннотированных классов, необходимо указать

<mvc:annotation-driven> 

так, что Spring создает бобы, которые будут реально отображающие методы обработки ваших @COntroller ФАСОЛЕЙ в пути URL.

Сделайте это в контексте, загруженном DispatcherServlet, т.е. servlet-context.xml.


Обратите внимание, что если вы указали

<context:component-scan .../> 

вам не нужно

<context:annotation-config /> 
+0

Спасибо за ваш ответ. Но не повезло с этим ... После добавления '', я столкнулся с той же проблемой. –

+0

@AbhendraSingh Создайте свой контроллер для '/ bookstore/authentication/login' –

+0

Я использовал [это] (http://stackoverflow.com/questions/11692837/url-mapping-issue-spring-web-mvc) в качестве справочника. Я думаю, что мне не нужно добавлять '/ bookstore' в Controller из-за' alwaysUseFullPath' (по умолчанию false). Я прав? –