After the context root of the spring Project is modified, the WebApplicationContext is initialized twice. spring initializes twice.
After the context root of the spring web project is modified to/, WebApplicationContext is initialized twice when the project is started. The following figure shows the initialization log:
First initialization:
April 22 4:30:33 org. apache. catalina. core. ApplicationContext log information: Initializing Spring root WebApplicationContext
Second initialization:
April 22 4:30:39 org. apache. catalina. core. ApplicationContext log information: Initializing Spring root WebApplicationContext
We can see that the two initialization operations are only 6 seconds apart..
Two initialization operations may cause many problems.
1. Question 1
During the second initialization, the number of connections to the database increases the number of initialization tasks. For example, the number of database connections initialized is:
InitialPoolSize = 20
SoThe second WebApplicationContext initialization will increase the number of connections to the database by 20. The first WebApplicationContext initialization will not release the database connection.!
Use select host, count (host) from information_schema.processlist; to view the number of connections;
You can also use the status directory to view the number of connections directly:
mysql> select host, count(host) from information_schema.processlist;+------+-------------+| host | count(host) |+------+-------------+| | 6 |+------+-------------+1 row in set (0.01 sec)mysql> status--------------mysql Ver 14.14 Distrib 5.6.27, for Win32 (x86)Connection id: 34Current database:Current user: ODBC@SSL: Not in useUsing delimiter: ;Server version: 5.6.27-log MySQL Community Server (GPL)Protocol version: 10Connection: localhost via TCP/IPServer characterset: utf8mb4Db characterset: utf8mb4Client characterset: utf8mb4Conn. characterset: utf8mb4TCP port: 3306Uptime: 8 hours 12 min 16 secThreads: 6 Questions: 20950 Slow queries: 0 Opens: 131 Flush tab--------------
Threads: 6 indicates that there are 6 connections.
2. Question 2
This will cause the dubbo consumer to register twice.
....
3. solution:
1) You can add nginx at the front end of tomcat to point nginx to tomcat, so that you do not need to modify the project's context root directory;
2) You can directly package a project and decompress it to the ROOT directory of tomcat. In this way, you do not need to modify the context root directory of the project;
3) if it is still difficult to package and decompress it to the tomcat root directory, you can change the project name to ROOT, and then change the project context root /, you can directly publish it to the tomcat ROOT directory;
You do not need to package and decompress the package;