我正在使用Tomcat 7和Spring MVC 3.2.x RELEASE。 Spring模板代码由Intellij生成,我刚刚添加了一个syserr消息输出。
当我启动服务器时,默认控制器被调用三次,并且仅在启动时,之后才能正常工作。我这是配置错误还是错误?
以下是配置文件:
@Controller
@RequestMapping("/")
public class HelloController {
private static int t = 0;
@RequestMapping(method = RequestMethod.GET)
public String printWelcome(ModelMap model) {
model.addAttribute("message", "Hello world!");
System.err.println("Print num: " + (++t));
return "hello";
}
}
//输出
INFO: Root mapping to handler 'helloController'
Jun 22, 2013 1:41:21 AM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'mvc-dispatcher': initialization completed in 413 ms
[2013-06-22 01:41:21,561] Artifact SpringTest:war exploded: Artifact is deployed successfully
Print num: 1
Print num: 2
Print num: 3
Jun 22, 2013 1:41:22 AM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/favicon.ico] in DispatcherServlet with name 'mvc-dispatcher'
Jun 22, 2013 1:41:30 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Users\Milky\apache-tomcat-7.0.41\webapps\manager
<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"
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">
<context:component-scan base-package="com.springapp.mvc"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Spring MVC Application</display-name>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
答案 0 :(得分:0)
使用Intellij IDEA
时(当应用程序启动时),可以调用сontroller方法三次 - 因为服务器配置"After launch"
设置。
您可以尝试取消选择它:screenshot from server configuration