2014-10-06 5 views
0

이것은 web.xml이며 Intellij가 생성했기 때문에 정확해야합니다. 스프링 MVC에서 URI 매핑을 찾을 수 없습니다.

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 
     version="3.1"> 
    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/applicationContext.xml</param-value> 
    </context-param> 
    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 
    <servlet> 
     <servlet-name>dispatcher</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>dispatcher</servlet-name> 
     <url-pattern>*.form</url-pattern> 
    </servlet-mapping> 
</web-app> 

@Controller 
public class IndexController { 

    @RequestMapping("/index") 
    public String index(ModelMap model) { 

     System.out.print("index"); 
     return "index"; 
    } 
} 

나는 인 IntelliJ에서 새 프로젝트를 만들

, 나는 이러한 옵션을 체크 컨트롤러입니다.

Java EE > Web Application 
    > Spring MVC 
    > Hibernate 

내가 사용하는 경우 내가 페이지를 올바르게

에 액세스 할 수 없습니다 "로컬 호스트 : 8080/테스트"

이 URL에 액세스하기 때문에 나는, 컨트롤러가 실행되지 않는 페이지를 볼 수 있지만 " 로컬 호스트 :/index.jsp를 localhost "를

내가 사용하는 경우"/ 테스트 8080 : 8080/테스트/지수 ", 결과는 404

내가 사용하는 경우"로컬 호스트 : 8080/테스트/지수 ", 결과는 404입니다 , 서버 이 오류

WARNING: No mapping found for HTTP request with URI [/test/index.form] in DispatcherServlet with name 'dispatcher' 

나는 ".form"을 "/"변화를 보여줍니다 로그,하지만, 난 여전히 같은 오류가 발생했습니다.

내 프로젝트에 아직없는 것이 있습니까?


업데이트, 이러한 applicationContext.xml 및 디스패처-servlet.xml 파일이며,이 파일은

applicationContext.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" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> 

</beans> 

디스패처-servlet.xml에

인 IntelliJ

에 의해 생성된다
<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="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.xsd"> 

</beans> 
+0

당신은 즉의 GET/POST, 메소드 레벨에서 방법의 유형을 넣어하려고 했습니까? – Neeraj

+0

Dispatcher Spring Config를 게시 할 수 있습니까? 그리고 봄 버전이 사용 되나요? –

+0

@Neeraj'method = RequestMethod.GET'을 시도했지만 작동하지 않습니다. –

답변

2

IndexController은 (는) 봄에서 발견되지 않습니다. @Controller를 추가했지만 Spring에로드하지 않았다는 것을 알려주지 않았습니다. dispatcher-servlet.xml을 변경하고 추가하십시오. 여기서 중요한 부분은 context:component-scan입니다.이 부분은 Spring이 패키지 내부에 주석이 달린 클래스를 찾도록 지시합니다.

여기를 참고하십시오. http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-ann-controller

<?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:mvc="http://www.springframework.org/schema/mvc" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 
     http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> 

    <context:component-scan base-package="<your controller package here>" /> 

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

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

</beans> 
관련 문제