Spring配置文件被加载两次问题
来源:互联网 发布:端口映射软件手机版 编辑:程序博客网 时间:2024/05/16 18:19
问题描述
今天在用spring quartz做定时任务的时候,用到了一个在程序启动时加载的配置方法init-method="loadJobInit",用来初始化在数据库中已经保存的定时任务,但是在程序启动之后发现该方法每个任务被执行了两次。
后来经过测试发现自己的Spring配置文件被加载了两次。
06-Dec-2016 14:43:16.311 INFO [RMI TCP Connection(3)-127.0.0.1] org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions Loading XML bean definitions from ServletContext resource [/WEB-INF/dispatcher-servlet.xml]06-Dec-2016 14:43:16.866 INFO [RMI TCP Connection(3)-127.0.0.1] org.springframework.web.servlet.handler.SimpleUrlHandlerMapping.registerHandler Mapped URL path [/**] onto handler 'org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler#0'06-Dec-2016 14:43:16.955 INFO [RMI TCP Connection(3)-127.0.0.1] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.register Mapped "{[/test]}" onto public java.lang.String com.test.TestControl.test()06-Dec-2016 14:43:17.052 INFO [RMI TCP Connection(3)-127.0.0.1] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.initControllerAdviceCache Looking for @ControllerAdvice: Root WebApplicationContext: startup date [Tue Dec 06 14:43:16 CST 2016]; root of context hierarchy06-Dec-2016 14:43:17.142 INFO [RMI TCP Connection(3)-127.0.0.1] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.initControllerAdviceCache Looking for @ControllerAdvice: Root WebApplicationContext: startup date [Tue Dec 06 14:43:16 CST 2016]; root of context hierarchy06-Dec-2016 14:43:17.237 INFO [RMI TCP Connection(3)-127.0.0.1] org.springframework.web.context.ContextLoader.initWebApplicationContext Root WebApplicationContext: initialization completed in 1104 ms06-Dec-2016 14:43:17.248 INFO [RMI TCP Connection(3)-127.0.0.1] org.springframework.web.servlet.DispatcherServlet.initServletBean FrameworkServlet 'dispatcher': initialization started06-Dec-2016 14:43:17.252 INFO [RMI TCP Connection(3)-127.0.0.1] org.springframework.web.context.support.XmlWebApplicationContext.prepareRefresh Refreshing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Tue Dec 06 14:43:17 CST 2016]; parent: Root WebApplicationContext06-Dec-2016 14:43:17.253 INFO [RMI TCP Connection(3)-127.0.0.1] org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions Loading XML bean definitions from ServletContext resource [/WEB-INF/dispatcher-servlet.xml]
解决方法
之前我的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/dispatcher-servlet.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>/</url-pattern> </servlet-mapping></web-app>
原来<listener>和<servlet>中的配置都是用来加载Spring配置的,一种是基于Servlet2.3版本中新引入的Listener接口实现,而另一种是基于Servlet接口实现。
<context-para>用来指定文件位置。
之前一直以为<listener>是用来监听@RequestMapping注解的。两个功能相同,在删除了<listener>注解之后问题就解决了。
参考资料:http://www.tmser.com/post-116.html
1 1
- Spring配置文件被加载两次问题
- Spring配置文件被加载两次问题
- Spring 初始化加载两次
- tomcat加载两次spring
- spring-servlet.xml 和 application.xml 配置含义及bean被加载两次的问题
- eclipse下启动服务 spring加载两次的问题
- 在eclipse 中启动spring 时加载两次的问题
- Tomcat加载两次问题
- 关于加载Spring配置文件的问题
- Spring+SpringMVC重复加载配置文件问题
- Spring 加载xml配置文件路径问题
- Spring配置文件加载外部配置文件
- spring配置文件加载
- spring多配置文件加载
- spring 加载配置文件
- Spring配置文件加载流程
- spring加载xml配置文件
- spring加载配置文件
- 裁剪image
- 微信广告调研
- dsp28335 Ecap总结
- 关于Mac上开发Qt的学习笔记
- Markdown语法指南
- Spring配置文件被加载两次问题
- 数据库常用的函数
- 3DCT 各向同性
- 遇到问题---java---git下载的maven项目web用tomcat发布时不带子项目
- 微信网页二维码扫描
- Linux设备驱动之mmap设备操作(memdev.c字符设备驱动分析)
- quartz.properties
- High-speed Charting Control--MFC绘制图表(折线图、饼图、柱形图)控件
- Python 实现感知器模型、两层神经网络