2013-08-02 52 views
0

我的應用在本地tomcat 7上正常工作,但在prod tomcat 7上只有索引url(「/」)和資源url工作,其他url沒有找到,「 /登錄「例如。Spring 3 MVC - 在生產中找不到Url映射(404)

的servlet-context.xml的

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

<annotation-driven /> 

<resources mapping="/resources/**" location="/resources/" /> 

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

<!-- FreeMarker View Resolver --> 
<beans:bean id="viewResolver" 
    class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"> 
    <beans:property name="cache" value="true" /> 
    <beans:property name="prefix" value="" /> 
    <beans:property name="suffix" value=".html" /> 
</beans:bean> 

<context:component-scan base-package="com.x.y" /> 

</beans:beans> 

的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"> 

<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>/WEB-INF/spring/root-context.xml</param-value> 
</context-param> 

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

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

試圖解決我改變了Servlet映射從<url-pattern>/</url-pattern><url-pattern>/*</url-pattern>和我沒有成功,但它開始尋找如果我把後綴名爲「.jsp」,例如:/login.jsp。

任何人都可以幫助我理解爲什麼tomcat正在等待這個「.jsp」後綴?我甚至使用JSP在我的應用程序:■

控制器樣品:

@Controller 
public class Application extends BaseController { 

    //... 

    @RequestMapping(value = "/", method = RequestMethod.GET) 
    public String index(Model model, HttpSession session) { 
     //.. 
     return "application/index"; 
    } 

     @RequestMapping(value = "/login", method = RequestMethod.GET) 
    public String login(Model model, HttpSession session) { 
     //.. 
     return "application/login"; 
    } 

    //... 
} 

感謝。

+0

如果你的應用程序行爲不同,那肯定是因爲tomcat(或其他)在生產中配置不一樣。但很難再告訴你:如果你的應用程序在你的本地tomcat上運行,那麼你的配置可能沒問題。 – mael

+0

我發現如果我在URL中找到映射後綴「.do」。奇怪的是什麼。 – ipfaffen

回答

0

聽起來就像你在生產環境中可能有apache坐在tomcat的前面,它只能通過特定的URL,例如:* .jsp 或者,它可能是防火牆阻止某些URL。