2010-05-11 3 views
2

내가 추가하는 모든 서블릿에 대한 새로운 설정 파일을 필요로하지 않도록 스프링 MVC 구성을 개선하려고하지만 문제가있다. 나는 this tutorial을 시작점으로 사용해 보았지만, 나는 알아 내지 못하는 문제에 직면하고있다.스프링 MVC 주석 설정 문제

문제점은 내 서블릿에 GET 할 때 404 오류가 발생한다는 것입니다. 여기 내 설정입니다 및 대표 자바는 컨트롤러에서 니펫을 :

의 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"> 
    <display-name>SightLogix Coordination System</display-name> 

    <description>SightLogix Coordination System</description> 

    <servlet> 
     <servlet-name>Spring MVC Dispatcher Servlet</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
      <init-param> 
       <param-name>contextConfigLocation</param-name> 
       <param-value> 
        /WEB-INF/application-context.xml 
        /WEB-INF/application-security.xml 
       </param-value> 
      </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 

    <servlet-mapping> 
     <servlet-name>Spring MVC Dispatcher Servlet</servlet-name> 
     <url-pattern>/slcs/*</url-pattern> 
    </servlet-mapping> 

    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value> 
      /WEB-INF/application-context.xml 
      /WEB-INF/application-security.xml 
     </param-value> 
    </context-param> 

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

    <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> 
</web-app> 

응용 프로그램의 context.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:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
     http://www.springframework.org/schema/mvc 
     http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context-3.0.xsd" 

    default-init-method="init" default-destroy-method="destroy"> 

    <mvc:annotation-driven /> 

    <context:component-scan base-package="top.level" /> 
</beans> 

응용 프로그램-security.xml :

<beans:beans xmlns="http://www.springframework.org/schema/security" 
    xmlns:beans="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd"> 

    <http> 
     <intercept-url pattern="/**" access="ROLE_MANAGER" requires-channel="https" /> 
     <http-basic /> 
    </http> 

    <authentication-manager> 
     <authentication-provider user-service-ref="myUserDetailsService"> 
      <password-encoder hash="sha"/> 
     </authentication-provider> 
    </authentication-manager> 

    <beans:bean id="myUserDetailsService" 
     class="path.to.my.UserDetailsServiceImpl"> 
    </beans:bean> 

</beans:beans> 

컨트롤러 클래스의 스 니펫 (많은 것 중 하나이지만이 모든 것이 본질적으로 비슷합니다) :

@Controller 
@RequestMapping("/foo.xml") 
public class FooController 
{  
    @RequestMapping(method=RequestMethod.GET) 
    public void handleGET(HttpServletRequest request, HttpServletResponse response) throws IOException 
    { 
     ... 

누구나 내가 잘못하고있는 것을 말할 수 있습니까? 감사합니다.

+0

/slcs/foo.xml을 HTTPS의 URL로 사용하고 있습니까? –

+0

@TaylorL : 예, 있습니다. – Seth

답변

3

여기 장소 중 유일한 것은 루트 웹 애플리케이션 컨텍스트 에 동일한 상황에 맞는 설정 파일을 사용한 적이 있다는 것입니다 :

다음은 내가 일반적으로 내 logging.properties 파일에서 사용하는 두 개의이다 서블릿 컨텍스트. 이것은 거의 나쁜 아이디어로 보장되어 이상한 행동을하게됩니다. 이것이 문제의 원인 일 수 있습니다.

ContextLoaderListenercontextConfigLocation<context-param>으로 구성되고 루트 WebApplicationContext을 만들고 관리합니다.

ServletDispatcherServletcontextConfigLocation<init-param>으로 구성되며 서블릿 WebApplicationContext을 생성하고 관리합니다.

루트 WebApplicationContext은 서블릿 appcontext의 부모입니다. 즉 루트 WebApplicationContext에있는 모든 bean은 서블릿의 해당 bean에 표시됩니다. WebApplicationContext.

첫 번째 단계는 이러한 구성을 분리하는 것입니다. 올바른 위치에 올바른 빈을 추가하십시오 (예 : 모든 MVC 항목이 서블릿 컨텍스트로 이동해야 함). 두 가지 사이의 bean 정의를 공유하지 않는다면 혼란 스럽거나 깨져 버릴뿐입니다.

+0

그런 종류의 구성으로 서블릿 초기화 매개 변수는 빈 bean 정의 파일을 가리켜 야합니다. 즉, 컨텍스트 로더 수신기가 모든 빈을로드 할 것이고 디스패처 서블릿이로드 될 때 모두 스스로 재정의됩니다. 원칙적으로 MVC를 서블릿의 특정 구성 파일로 분리하는 것에 동의하지만,이 경우에는 서블릿이 하나만 있으므로 실제로는 필요하지 않습니다. 두 개 이상의 서블릿이 튀어 나오면 그 분리가 더 중요해집니다. – MetroidFan2002

+0

내 응용 프로그램과 서블릿에 대한 컨텍스트 파일을 분리했지만 여전히 404 오류가 발생합니다. – Seth

0

이 질문에 대한 답변을 직접 작성한 것은 아니지만 문제가 무엇인지 알 수 없을 때 Spring에서 디버그 로깅을 사용하는 것이 도움이된다는 것을 항상 발견했습니다.

org.springframework.beans.factory.support.level=FINEST 
org.springframework.security.level=FINEST 
0

컨트롤러에 GET RequestMapping이 두 개 이상 있습니까? 둘 이상이 있고 특정 요청에 대한 해결 방법이 모호한 경우 Spring은 모호한 GET 매핑으로 매핑하지 않습니다.