Java 弹簧控制器';在根(/)上下文下本地部署到Tomcat wep应用程序时,在启动时调用的

Java 弹簧控制器';在根(/)上下文下本地部署到Tomcat wep应用程序时,在启动时调用的,java,eclipse,spring,spring-mvc,tomcat,Java,Eclipse,Spring,Spring Mvc,Tomcat,我有一个非常简单的Spring MVC应用程序,其中我配置了dispatcher servlet以接受/模式下的请求,如下所示: <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLo

我有一个非常简单的Spring MVC应用程序,其中我配置了dispatcher servlet以接受/模式下的请求,如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<web-app 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_3_0.xsd"
          version="3.0">

    <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>/</url-pattern>
    </servlet-mapping>

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

</web-app>
现在我想在Tomcat中部署我的web应用程序,并将web上下文根设置为/,这样当点击localhost:8080时,我的索引页就会弹出。 这确实工作正常,但问题是在启动过程中调用了该方法,spring记录了相同的日志,但没有任何浏览器或其他东西来请求该页面

为了从Eclipse更改web应用程序的上下文路径,我正在使用modules选项卡中的上下文描述符

我尝试的是:

i) 通过添加下面的jboss-web.xml,同样的战争在荒野中进行,并且它工作正常,没有在启动时调用/*路径

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
    <context-root>/</context-root>
</jboss-web>
服务器日志:

INFO: Server startup in 14690 ms
2016-08-17 18:25:53 [http-bio-8080-exec-1] DEBUG DispatcherServlet:823 - DispatcherServlet with name 'dispatcher' processing GET request for [/]
2016-08-17 18:25:53 [http-bio-8080-exec-1] DEBUG RequestMappingHandlerMapping:220 - Looking up handler method for path /
2016-08-17 18:25:53 [http-bio-8080-exec-1] DEBUG RequestMappingHandlerMapping:227 - Returning handler method [public org.springframework.web.servlet.ModelAndView com.controller.MainController.index(javax.servlet.http.HttpSession,javax.servlet.http.HttpServletRequest)]
2016-08-17 18:25:53 [http-bio-8080-exec-1] DEBUG DefaultListableBeanFactory:246 - Returning cached instance of singleton bean 'mainController'
2016-08-17 18:25:53 [http-bio-8080-exec-1] DEBUG DispatcherServlet:912 - Last-Modified value for [/] is: -1
735E606472EA914D4099265BD47474FA
Java/1.8.0_20
2016-08-17 18:25:56 [http-bio-8080-exec-1] DEBUG DefaultListableBeanFactory:1525 - Invoking afterPropertiesSet() on bean with name 'index'
2016-08-17 18:25:56 [http-bio-8080-exec-1] DEBUG DispatcherServlet:1206 - Rendering view [org.springframework.web.servlet.view.JstlView: name 'index'; URL [/WEB-INF/jsp/index.jsp]] in DispatcherServlet with name 'dispatcher'
2016-08-17 18:25:56 [http-bio-8080-exec-1] DEBUG JstlView:236 - Forwarding to resource [/WEB-INF/jsp/index.jsp] in InternalResourceView 'index'

通过命令行部署显示了相同的问题?
System.out.println
应该提供一些输出,但您发布的日志不包含这样的输出。你认为为什么会调用这个方法?@serg.nechaev-nope,如果我将它部署为ROOT.war并手动启动tomcat,一切都正常。@AntJavaDev啊,好的。请把代理打印到控制台上好吗?只需使用
(HttpSession session,HttpServletRequest req)
而不是
(HttpSession session)
,并添加行
System.out.println(req.getHeader(“用户代理”)@AntJavaDev哦,这可能就是答案。我记得在集成中,eclipse注意到一个成功的webcontainer启动,并在eclipse中打开了一个新的webbrowser视图。这可能是你的幻影请求。“ant java丢失了一个请求。多么尴尬啊……”
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
    <context-root>/</context-root>
</jboss-web>
    @RequestMapping("/*")
    public ModelAndView index(HttpSession session,HttpServletRequest req) 
    {
        System.out.println(session.getId());
        System.out.println(req.getHeader("user-agent"));
        return new ModelAndView("index");
    }
INFO: Server startup in 14690 ms
2016-08-17 18:25:53 [http-bio-8080-exec-1] DEBUG DispatcherServlet:823 - DispatcherServlet with name 'dispatcher' processing GET request for [/]
2016-08-17 18:25:53 [http-bio-8080-exec-1] DEBUG RequestMappingHandlerMapping:220 - Looking up handler method for path /
2016-08-17 18:25:53 [http-bio-8080-exec-1] DEBUG RequestMappingHandlerMapping:227 - Returning handler method [public org.springframework.web.servlet.ModelAndView com.controller.MainController.index(javax.servlet.http.HttpSession,javax.servlet.http.HttpServletRequest)]
2016-08-17 18:25:53 [http-bio-8080-exec-1] DEBUG DefaultListableBeanFactory:246 - Returning cached instance of singleton bean 'mainController'
2016-08-17 18:25:53 [http-bio-8080-exec-1] DEBUG DispatcherServlet:912 - Last-Modified value for [/] is: -1
735E606472EA914D4099265BD47474FA
Java/1.8.0_20
2016-08-17 18:25:56 [http-bio-8080-exec-1] DEBUG DefaultListableBeanFactory:1525 - Invoking afterPropertiesSet() on bean with name 'index'
2016-08-17 18:25:56 [http-bio-8080-exec-1] DEBUG DispatcherServlet:1206 - Rendering view [org.springframework.web.servlet.view.JstlView: name 'index'; URL [/WEB-INF/jsp/index.jsp]] in DispatcherServlet with name 'dispatcher'
2016-08-17 18:25:56 [http-bio-8080-exec-1] DEBUG JstlView:236 - Forwarding to resource [/WEB-INF/jsp/index.jsp] in InternalResourceView 'index'