2013-08-02 56 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。