2011-04-14 50 views
5

我有一個問題,我的春天項目。問題與InternalResourceViewResolver和Winstone

這裏是我的web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
     http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 

    <servlet> 
     <servlet-name>greenmine</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 

    <servlet-mapping> 
     <servlet-name>greenmine</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 

    <welcome-file-list> 
     <welcome-file> 
      index.jsp 
     </welcome-file> 
    </welcome-file-list> 

    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value> 
      /WEB-INF/greenmine-servlet.xml 
     </param-value> 
    </context-param> 

    <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>/*</url-pattern> 
    </filter-mapping> 

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

和我greenmine-servlet.xml中

<?xml version="1.0" encoding="UTF-8"?> 

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:security="http://www.springframework.org/schema/security" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xsi:schemaLocation="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/security 
     http://www.springframework.org/schema/security/spring-security-3.0.3.xsd 
     http://www.springframework.org/schema/mvc 
     http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> 

    <context:component-scan base-package="at.tripwire.greenmine.controller" /> 
    <context:component-scan base-package="at.tripwire.greenmine.domain.dao" /> 
    <context:component-scan base-package="at.tripwire.greenmine.service" /> 
    <context:component-scan base-package="at.tripwire.greenmine.module" /> 

    <mvc:annotation-driven /> 
    <mvc:resources location="/css/" mapping="/css/**" /> 
    <mvc:resources location="/images/" mapping="/images/**" /> 
    <mvc:resources location="/js/" mapping="/js/**" /> 

    <bean id="viewResolver" 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> 
     <property name="prefix" value="/WEB-INF/jsp/" /> 
     <property name="suffix" value=".jsp" /> 
    </bean> 

    <!-- Hibernate Configuration --> 
    <bean id="dataSource" 
     class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
     <property name="driverClassName"> 
      <value>com.mysql.jdbc.Driver</value> 
     </property> 
     <property name="url"> 
      <value>jdbc:mysql://localhost/greenmine</value> 
     </property> 
     <property name="username"> 
      <value>root</value> 
     </property> 
     <property name="password"> 
      <value>root</value> 
     </property> 
    </bean> 

    <bean id="sessionFactory" 
     class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> 
     <property name="annotatedClasses"> 
      <list> 
       <value>at.tripwire.greenmine.domain.Project</value> 
       <value>at.tripwire.greenmine.domain.Profile</value> 
      </list> 
     </property> 
     <property name="hibernateProperties"> 
      <props> 
       <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop> 
       <prop key="hibernate.hbm2ddl.auto">update</prop> 
      </props> 
     </property> 
     <property name="dataSource"> 
      <ref bean="dataSource" /> 
     </property> 
    </bean> 

    <!-- Spring Security --> 
    <security:http auto-config="true" use-expressions="true"> 
     <security:intercept-url pattern="/login" 
      access="permitAll" /> 
     <security:intercept-url pattern="/j_spring_security_check" 
      access="permitAll" /> 
     <security:intercept-url pattern="/css/**" 
      filters="none" /> 
     <security:intercept-url pattern="/js/**" 
      filters="none" /> 
     <security:intercept-url pattern="/images/**" 
      filters="none" /> 
     <security:intercept-url pattern="/**" 
      access="isAuthenticated()" /> 
     <security:form-login login-page="/login" 
      login-processing-url="/j_spring_security_check" default-target-url="/projects" 
      authentication-failure-url="/login?error=1" /> 
     <security:logout logout-success-url="/login" 
      logout-url="/logout" /> 
    </security:http> 

    <security:authentication-manager> 
     <security:authentication-provider 
      user-service-ref="profileUserDetailsService"> 
      <security:password-encoder hash="md5" /> 
     </security:authentication-provider> 
    </security:authentication-manager> 
</beans> 

下一個:我LoginController.java

@Controller 
public class LoginController { 

    @RequestMapping("/login") 
    public ModelAndView handleLoginForm(HttpServletRequest request) { 
     String errParam = request.getParameter("error"); 
     ModelAndView mv = new ModelAndView("login/login"); 
     if(errParam != null) { 
      mv.addObject("error", "Benutzer oder Kennwort unzul&auml;ssig"); 
     } 
     return mv; 
    } 
} 

我使用溫斯頓Servlet引擎v0.9.10。 當我轉到http://localhost:8080/login它把下列錯誤:

14.04.2011 21:48:13 org.springframework.web.servlet.DispatcherServlet noHandlerFound 
WARNUNG: No mapping found for HTTP request with URI [/WEB-INF/jsp/login/login.jsp] in DispatcherServlet with name 'greenmine' 

但login.jsp的是在WEB-INF/JSP /登錄/ login.jsp的

希望有人能幫助我。我已經在尋找兩個星期了。

+0

沒有人能幫助我嗎? – endian 2011-04-18 07:09:21

回答

2

以下標籤解決我的問題:

<mvc:default-servlet-handler/> 
0

你只需要一個處理程序添加到配置..

看你的代碼,你可以添加以下行來解決該問題

<bean class=" org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/> 
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> 

我們說annotaions是要由DefaultAnnotationHandler類處理此類知道如何根據註釋定義控制器 和AnnotationMethodHandlerAdapter瞭解方法的註釋(如@RequestMapping)時應如何操作。

+0

我在我的greenmine-servlet.xml中添加了這兩行,但沒有任何更改。 – endian 2011-04-19 19:51:05