Spring 3 MVC - 在生产中找不到(404)Url映射

时间:2013-08-02 17:50:16

标签: java spring rest tomcat spring-mvc

我的应用程序在本地tomcat 7上工作正常,但在prod tomcat 7上只有索引url(“/”)和资源url工作,找不到其他url,例如“/ login”。

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”后缀?我甚至没有在我的app中使用jsp:s

控制器示例:

@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";
    }

    //...
}

感谢。

1 个答案:

答案 0 :(得分:0)

听起来你可能在你的生产环境中坐在tomcat前面的apache,它只通过某些url,例如:* .jsp 或者,它可能是阻止某些URL的防火墙。