Category Archives: How to Fix

Spring boot project running error: Servlet.service () for servlet [dispatcherServlet] threw exception

spring boot
spring boot
spring boot
spring boot
spring boot
spring boot
Error output from console:

2020-06-29 12:25:44.780 ERROR 1968 --- [nio-8080-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] threw exception

java.lang.StackOverflowError: null
	at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:583) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:583) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:583) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:583) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:583) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:583) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:583) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:583) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	

: The @Autowired annotation is not added to the implementation class in the Service layer. This will cause the implementation class to lack dependencies. An error will occur if the dependencies cannot be found after the project is started.
Original code:

   private EmployeeDao employeeDao;

Modified code after adding annotations:

 @Autowired
   private EmployeeDao employeeDao;

The problem is resolved by adding the @Autowired annotation.

Setting up a virtual environment for jupyter notebook

After create the virtual environment, start jupyter can’t find the environment, the solution is as follows:
1. First activate the virtual environment

activate py3

2. Install ipykernel

conda install ipykernel

3. Create the kernel file

conda install -n py3 ipykernel

4. Write the environment into the Notebook kernel

python -m ipykernel install --user --name py3 --display-name "py3"

The first Py3 is the name of the virtual environment, and the second Py3 is the name displayed in the Jupyter.

The process of creating the virtual environment is really bumpy. I just encountered another problem. After creating a new Notebook, it keeps showing that it is connecting to the service.
pip uninstall tornado pip install tornado==5.0.0

Reference links

add conda jupyter environment jupyter notebook open file times wrong: the connection to backend service failed to build a…

Leetcode-234: palindrome linked list

Topic describes
Determine whether a linked list is a palindrome list.
// 1 2 nil
// 1 2 1 nil
// 1 2 2 1 nil
Thought analysis
The fast and slow pointer finds the midpoint of the linked list and splits the midpoint and reverses the tail list to compare whether the values of the head and tail list are equal in turn
Code implementation

func isPalindrome(head *ListNode) bool {
	if head == nil {
		return true
	}
	fast := head.Next
	slow := head
	for fast != nil && fast.Next != nil {
		fast = fast.Next.Next
		slow = slow.Next
	}

	tail := reverse(slow.Next)
	slow.Next = nil

	for head != nil && tail != nil {
		if head.Val != tail.Val {
			return false
		}
		head = head.Next
		tail = tail.Next
	}
	return true
}

func reverse(head *ListNode) *ListNode {
	if head == nil {
		return head
	}
	var pre *ListNode
	for head != nil {
		temp := head.Next
		head.Next = pre
		pre = head
		head = temp
	}
	return pre
}

Export and import method of MySQL under Linux

Mysql export
Several Methods of Database

 

Methods a

Mysql> mysqldump — opt-h192.168.0.156-uusername-ppassword –skip-lock-tables databasename> The database. SQL

Change the IP address to localhost and you can use www.2cto.com

If Navicate is installed, then it is even easier to connect to the database, select the database, and then dump the SQL

Method 2

Enter CMD (note in OS CMD and not in MySQL)

= = = = = = = = = = = = = = = = = = =

1. Export database (SQL script)

Mysqldump -u username -p database name> Export filename

mysqldump -u root -p db_name > test_db.sql

Mysql> export a table from mysql

Mysql> mysqldump -u -p; Export filename

mysqldump -u wcnc -p test_db users> Test_users.sql (no semicolon at the end)

Methods three

Mysql> start mysql

/etc/init.d/mysql start

Export the entire database

mysqldump dbname > C: mydb. SQL -u root -p

Import the database

source mydb.sql

Mysql -u username -p database name < Database name.sql

More detailed database import tutorial

www.2cto.com

2.1. Export SQL Scripts

From the original database server, you can export SQL scripts using the PHP tutorial myadmin tool or the mysqldump command line (mysqldump command is located in the mysql/bin/ directory).

2.1.1 Use the phpMyAdmin tool

In the export options, select export “structure” and “data” and do not add “drop database” and “drop table” options.

Select the “save as file” option, or if you have a lot of data, select the “gzipped” option.

Save the exported SQL file.

2.1.2 Use the mysqldump command line

The command format

Mysqldump -u username -p database name> Database name.sql

Example:

mysqldump -uroot -p abc > abc.sql

Export database ABC to ABC. SQL file

When prompted for a password, enter the password for the user name of the database.

2.2. Create an empty database

From the master interface/control panel, create a database. Assume that the database name is ABC and the database full user is ABC_F.

2.3. Import SQL script for execution

There are also two methods, one using phpMyAdmin (my)
SQL database management tools, or
MySQL command line.

2.3.1 Use the phpMyAdmin tool

From the control panel, select the empty database to create, and click “Manage” to go to the admin tools page.

In the “SQL” menu, browse and select the exported SQL file, and click “Execute” to upload and execute.

Note: phpMyAdmin has a limit on the size of uploaded files, and PHP itself has a limit on the size of uploaded files, if the original SQL file is used

It is relatively large, you can use gzip to compress it first, for text files such as SQL files, you can get 1:5 or more compression ratio.

How to use gzip: www.2cto.com

# gzip xxxxx.sql

get

XXXXX. SQL. Gz file.

2.3.2 Use the MySQL command line

The command format

Mysql -u username -p database name < Database name.sql

Example:

mysql -uabc_f -p abc < abc.sql

Import database ABC from ABC. SQL file

When prompted for a password, enter the password for the user name of the database.

Usually, you may use a lot of MySQL import and export methods, today I will introduce you several import and export MySQL data methods, convenient for you to use in work.
Here’s what Baidu got:

Mysql> import files or data or execute related SQL

    1

    Mysql -h host address -u user name -p user password mysql -h host address -u user name -p user password (shell command line)
    mysql -u root -p dbname < filename.sql

    2

    Execute an SQL
    directly on the command line (shell command line)
    mysql -hhostname -uusername -p dbname -e ‘select * from tbname limit 1’
    After execution, the command line will prompt for the database password.

    3

    echo ‘select id from dbname.tbname where id = 1; ‘ | mysql -hhostname -ureadonly -preadonly dbname > xxxx.sql

    4

    Enter the MySQL database (where the SQL file is executed)
    > source xxx.sql

    END

Mysqldump = mysqldump;

    1

    Mysqldump -u user name -p password -h host database a-w “SQL condition” — lock-all-tables>; Path
    mysqldump -hhostname -uusername -p dbname tbname> xxxx.sql

    2

    ** Export the contents of the database table on the specified criteria. (-w option — where)
    mysqldump -hhostname -uusername-p dbname tbname -w’id > = 1 and id< = 10000′–skip-lock-tables > xxxx.sql

    3

    Or the next line is
    mysqldump -hhostname -uusername -p dbname tbname –where=’unit_id > = 1 and unit_id < = 10000′> ~/xxxx.sql

    END

Mysqldump Export Database Table

    1

    mysqldump -u username -p database name> Export file name
    > mysqldump -u breezelark-p mydb > mydb.sql

    2

    mysqldump -u username -p database name>
    mysqldump -u username -p database name> Export file name
    mysqldump -u lingxi -p mydb mytb> mytb.sql

    3

    Export a database structure (no data only structure)
    mysqldump -u lingxi -p -d –add-drop-table mydb > mydb.sql
    – d no data – add – drop – table before each the create statement adds a drop table
    of course this is just one way of import and export, you can feel the choice suits own method.

Import / export. SQL file / gzip file for MySQL under Linux

    ready. SQL file and upload to server login server MySQL import. SQL file
If you need to create the database for the entire database file you don’t need to create the database for the table file
Source *.sql //.sql file path
 
3. Export. SQL file
Export table structure
It’s going to be in the data directory
cd /mysql/data/
. /bin/mysqldump -uroot -p -d newdb > Newdb.sql // newdb database name
// Enter the password
 
Export data and table structures
It’s going to be in the data directory
cd /mysql/bin/
. /bin/mysqldump -uroot -p newdb > Newdb.sql // newdb database name
// Enter the password
 

    exports the gzip file
It’s going to be in the data directory
. /bin/mysqldump -uroot -p –default-character-set=utf8 xw_taes | gzip > /home/xw_taes_1.sql.gz
// Enter the password
 

    import gzip
In any directory
gzip -d < /home/xw_taes_1.sql.gz | mysql -uroot -p xw_taes_1
// Enter the password
Xw_taes_1 is the name of the database to import
There is no meeting

 
Note: Adding plaintext password directly will report an error

cvc-complex-type.2.3: Element ‘beans’ cannot have character [children]

When writing Spring’s ApplicationContext.xml file, out of nowhere:
CVC-Complex Type.2.3: Element ‘beans’ cannot have character [children], because the type’s content type is element-only. Error.

Error: Spring does not recognize the elements in ApplicationContext.xml when initialized.
Possible reasons for this error: The code copied online is pasted directly into an XML file, and the code on the Web may not conform to the XML specification

Remove the Chinese annotations from the XML file, because some of the annotations copied are not recognized by Spring.  
2. If there is still an error, try to modify the extra space, because Chinese space Spring may recognize the error.
3. Last resort: Copy the file again manually and save it.

Problems of accessing servlet display 404 on MyEclipse

Sometimes, when accessing a servlet in MyEclipse, a 404 page will appear. I won’t go into this if the web.xml is not configured properly or the URL is wrong, but I will talk about the situation where everything seems to be correct but I still can’t access it.
All you need to do is find the container where the servlet is running, in this case Tomcat, close it first, then locate the corresponding project in Tomcat, click ReDeploy, and then start Tomcat.