SpringMVC контроллер вызывается 3 раза

230
30 марта 2018, 12:49

Доброго времени суток. Есть код:

@Controller
public class MainController {
    private int callsNum = 0;
    @RequestMapping(value = "/", method = RequestMethod.GET)
    @Transactional
    public String helloWorld() {
        System.out.println(++callsNum);
        return "home";
    }
}

При развертывании приложения контроллер вызывается 3 раза:

В чём может быть проблема?

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <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>*.form</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

dispatcher-servlet.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="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 http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
    <!-- DispatcherServlet Context: defines this servlet's request-processing
          infrastructure -->
    <!-- Enables the Spring MVC @Controller programming model -->
    <mvc:annotation-driven />
    <!-- Handles HTTP GET requests for /resources/** by efficiently serving
        up static resources in the ${webappRoot}/resources directory -->
    <mvc:resources mapping="/resources/**" location="/resources/" />
    <context:component-scan base-package="com.ivansokolov" />
    <!-- Resolves views selected for rendering by @Controllers to .jsp resources
        in the /WEB-INF/views directory -->
    <bean
            class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/" />
        <property name="suffix" value=".jsp" />
    </bean>

</beans>

home.jsp:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>Hello World</title>
    <h3>Hello World!</h3>
  </head>
  <body>
  Hello!
  </body>
</html>
READ ALSO
Выделение ячеек в GridView?

Выделение ячеек в GridView?

ячейку при нажатии,какой обработчик делает жто?

242
Скачивание файла с прогрессом

Скачивание файла с прогрессом

Доброго времени сутокМне надо способ скачивать множество файлов одновременно по определённому пути в определённый каталог

256
Ссылки с помощью SpannableStringBuilder

Ссылки с помощью SpannableStringBuilder

Как убрать линии, которые находятся под текстом?

221
java.lang.OutOfMemoryError: Could not allocate JNI Env при чтении из сокета

java.lang.OutOfMemoryError: Could not allocate JNI Env при чтении из сокета

По таймеру слежу за сообщениями от сокет сервераСо временем программа вылетает

210