2014-02-13 2 views
0

간단한 Spring MVC 3 응용 프로그램을 만들고 freemarker 템플릿 엔진을 사용하려고합니다. * -context.xml은 Spring의 문서에서 설명하는대로 구성되지만 브라우저에서는 404 Page not found 오류가 발생합니다. HelloWorldController.javaSpring MVC 3에서 freemarker를 사용할 수 없습니다.

@Controller 
@RequestMapping("/hello") 
public class HelloWorldController { 

private static final Logger log = Logger.getLogger(HelloWorldController.class); 

@RequestMapping(value="/{name}", method = RequestMethod.GET) 
public String hello(@PathVariable String name, Model model) { 

    String result = "Hello, " + name; 
    model.addAttribute("result", result); 

    return "hello"; 
} 

} 

이 내 서블릿-context.xml에

WEB-INF/프리 마커 폴더

<!doctype html> 
<html> 
<head> 
    <title>Hello</title> 
</head> 
<body> 
<h1> 
    Hello world! 
</h1> 

<P> The time on the server is ${result}. </P> 
</body> 
</html> 

hello.ftl이며,이 내 코드입니다

<?xml version="1.0" encoding="UTF-8"?> 
<beans:beans xmlns="http://www.springframework.org/schema/mvc" 
    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.xsd 
     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"> 

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure --> 

    <!-- Enables the Spring MVC @Controller programming model --> 
    <annotation-driven /> 

    <!-- freemarker config --> 
    <beans:bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"> 
     <beans:property name="templateLoaderPath" value="/WEB-INF/freemarker/"/> 
    </beans:bean> 

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory --> 
    <resources mapping="/resources/**" location="/resources/" /> 

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory --> 
    <beans:bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"> 
     <beans:property name="prefix" value="" /> 
     <beans:property name="suffix" value=".ftl" /> 
     <beans:property name="cache" value="false" /> 
    </beans:bean> 

    <context:component-scan base-package="org.example.simple" /> 

</beans:beans> 

무엇이 잘못 되었습니까? 04 내가 localhost : 8080/simple/hello/username에 갈 때? ,

편집 도와주세요 :

web.xml에 스프링 MVC가 아닌 프리 마커에 대한

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

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

답변

1

는 아마 잘못 구성. 봄이 컨트롤러를 찾을 수없는 것 같습니다. dispatcherServlet을 web.xml에 추가 했습니까?

+0

예, 내 질문을 편집했습니다. web.xml에 대한 정보를 찾을 수 있습니다. –

+0

를 spring xml 구성에 추가하십시오. – freakman

+0

이 param은 이미 내 봄 xml –

관련 문제