When spring is combined, the web. xml configuration, spring is combined with web. xml

Source: Internet
Author: User

When spring is combined, the web. xml configuration, spring is combined with web. xml

 

<! -- 1. web. xml configuration <context-param> <param-name> webAppRootKey </param-name> <param-value> webapp. root </param-value> </context-param> "webapp. root "this string can be any character string. If the default value is "webapp. root ". You can use System. getProperty ("webapp. root") to dynamically obtain the running path of the project. Generally, the returned results include/usr/local/tomcat6/webapps/project name. 2. If the following error is returned for a Web project deployed in the same container, you must configure different <param-value>, it cannot be repeated. Otherwise, the following error is returned: Web app root system property already set to different value: 'webapp. root '= [/home/user/tomcat/webapps/project1/] instead of [/home/user/tomcat/webapps/project2/]-Choose unique values for the 'webapprootkey' context-param in your web. xml files! It means "webapp. root "this key already points to project 1 and cannot point to project 2.3. The Loading Method Spring uses org. springframework. web. util. the project path of the WebAppRootListener listener to run. However, if you have configured the listener org. springframework. web. util. Log4jConfigListener in web. xml, you do not need to configure WebAppRootListener. Because Log4jConfigListener already includes the WebAppRootListener function 4, it dynamically finds the project path in log4j at runtime. properties configuration file, you can use $ {webapp as follows. root}: log4j. appender. file. file =$ {webapp. root}/WEB-INF/logs/sample. log can dynamically find the project path at runtime --> <context-param> <param-name> webAppRootKey </param-name> <param-value> webapp. report. services </param-value> </context-param> <! -- This is the default path and default file name. You do not need to configure log4jConfigLocation. This parameter is configured for clarity. Otherwise, you need to configure this parameter value --> <context-param> <param-name> log4jConfigLocation </param-name> <param-value> classpath: log4j. properties </param-value> </context-param> <! -- The container will scan the log4j configuration file every 6 seconds. Dynamically change the record level and policy, that is, modify log4j. properties without restarting the Web application. --> <Context-param> <param-name> log4jRefreshInterval </param-name> <param-value> 6000 </param-value> </context-param> <context- param> <param-name> contextConfigLocation </param-name> <param-value> classpath: spring/spring-beans.xml </param-value> </context-param> <! -- Log4jConfigListener must be before ContextLoaderListener --> <listener-class> org. springframework. web. util. log4jConfigListener </listener-class> </listener> <listener-class> org. springframework. web. context. contextLoaderListener </listener-class> </listener> <listener-class> com. fangdd. report. basic. web. sessionListener </listener-class> </listener> <! -- SSH Memory leakage and Spring Quartz issues copyright statement: During reprinting, please mark the original source and author information of the article in the form of a hyperlink and refer to this statement. After debugging the system program, I copied the program again and renamed it TMT, but the published Web Name Is TM. Run with the same Tomcat. The problem occurred. After I modified it in the TMT project, the code in the TM project was RUN. I tried to delete the cached files in the WORK directory under TOMCAT 6 and Startup in the BIN directory of TOMCAT. add the following statement to the script header in bat: rd/s/q TMrd/s/q .. \ work \ Catalina \ localhost \ TM .. \ bin \ catalina start is useless. Add <Context path = "" docBase = "" debug = "0" reloadable = "true"/> to server. xml in the conf directory of TOMCAT6. After reload is done in the Tomcat manage, the program version cannot be updated. The running is the code in the previous TM project, the code linked database in the TMT project is different from the database linked to the TM project. The SQL statement executed by hibernate is displayed on the Console interface, I found that the database uses the database in the TM project, but the program I run is the TMT project. Speechless .... Try to clear the Eclipse cache and delete all subdirectories except the. settings subdirectory and config. ini file under [eclipsehome]/configuration. Still useless, still calling old programs. Finally, try to add the parameter-clean to start the myclipse shortcut. ========================================================== ================== Next, search for a solution in javaeye, I accidentally flipped through Struts + Spring + Hibernate Memory leakage to find and handle a post about Robbin, talking about using org. springframework. web. util. the IntrospectorCleanupListener listener handles the buffer leakage caused by the use of JavaBeans Introspector, Which is ideal for regular Scheduling with Quartz. The following excerpt is for future reference. ========================================================== ================ IntrospectorCleanupListener: "During server running, Spring keeps running scheduled tasks and OpenSessionInViewFilter, which causes Tomcat to repeatedly load objects to generate a framework and possibly cause memory leakage, use IntrospectorCleanupListener as the corresponding solution. "Reference: A listener named org. springframework. web. util. IntrospectorCleanupListener is provided in spring. It is mainly responsible for Handling Buffer leaks caused by the use of JavaBeans Introspector. Spring describes it as follows: it is a listener that clears JavaBeans Introspector when the web application is disabled. web. register this listener in xml. when the web application is closed, you can release the class loader related to the web application and the class managed by the web application. If you use JavaBeans Introspector to analyze the classes in the application, the Introspector buffer retains references to these classes. as a result, when your application is closed, these classes and class loaders related to web applications are not garbage collected. unfortunately, the only way to clear Introspector is to refresh the entire buffer. this is because we cannot determine which references belong to your application. therefore, deleting the buffered introspection will delete the introspection of all applications on this computer. note that spring-managed beans do not need to use this listener. because spring has its own introsp The buffer used by ection is immediately removed from the ans Introspector buffer after a class is analyzed. classes in applications never directly use JavaBeans Introspector. therefore, they generally do not cause leakage of internal viewing resources. however, some class libraries and frameworks often cause this problem. for example, Struts and Quartz. the leakage of a single internal view will prevent the class loaders of the entire web application from performing garbage collection. after the web application is disabled, you will see all static class resources of the application (for example, Singleton ). of course this error is not caused by this class. the usage is very simple, that is, in the web. add <listener> <listener-class> org. springframework. web. util. introspectorCleanupListener </listener-class> </listener >===================== ======== =, Self-thread scheduling. By default, a framework like Quartz starts 10 threads internally in the web container for asynchronous job scheduling, which is very dangerous, servlet thread resources can easily be recycled. Another problem with quartz is that it does not support cluster. As a result, no quartz application can be used as a cluster. The solution is to independently start a Job Server to run the job and will not be deployed in the web container. When other web nodes need to start asynchronous tasks, they can notify the Job Server in various ways (DB, JMS, Web Service, etc). After the Job Server receives the notification, load an asynchronous task to your task queue. In fact, it is not difficult to transform a web application that has already integrated quartz: for example, you can use a database table to record and maintain the task queue and status, and remove the quartz part from the web application completely, write a Java Main program to run the spring container configured with quartz, so that the Job Server starts (note that this Job Server is completely out of tomcat ). In addition, this Main program should start another sub-thread to regularly scan the list of database task teams: Add new tasks to the quartz task scheduling; write the execution status of the current task to the task table; after you see the table field status of the Delete task, delete the corresponding task. Then, the web application removes the quartz part of the configuration, and changes the code for calling the quartz task to read and write the database task table. In this way, the job part is completely removed from the web container, even the cluster of web containers is okay, and when multiple web nodes read and write the task table at the same time, there are database transactions to ensure operation consistency, which is really great. In addition, you can also create a separate job management interface. You can manually add tasks, view task statuses, and delete tasks on the web interface. --> <Listener-class> org. springframework. web. util. IntrospectorCleanupListener </listener-class> </listener>

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.