Recently, I made a low-level mistake in the project, which is very low. First, I posted the error message of my own program, and the information is as follows:
Error creating bean with name 'sqlSessionFactory' defined in class path resource []:
Initialization of bean failed; nested exception is :
Failed to convert property value of type '' to required type '' for property 'dataSource';
nested exception is : Cannot convert value of type '' to required type ''
for property 'dataSource': no matching editors or conversion strategy found
From the above error message, we can know that the reason for the error is that an error occurred while creating a bean named 'sqlSessionFactory', that is, creating a sqlSessionFactory with mybatis failed. The reason for the failure is that the string configured in your datasource cannot be converted into an object, resulting in the SessionFactory being unable to complete.
Go hereWe can clearly know that the datasource configuration must be incorrect, so we have to check the data source we configured in the file,
Open the file and I found that the code I wrote to configure the data source is like this:
<property name="dataSource" value="dataSource">
Look, what I actually wrote is value here! I actually wrote value! ! I actually wrote value! ! ! My mentality is a bit broken.
So the value in the above sentence was changed to ref, as follows:
<property name="dataSource" ref="dataSource"/>
Let me explain it here,There is a difference between ref and value. The value corresponds to the attribute's value of the basic data type and string type. ref is the bean type configured in the corresponding current xml file.This concept is mine/qq_38701478/article/details/82778431This blog has been introduced, and if you don’t understand, you can check it out.
If we use value for injection here,Spring will be injected as a string, so it will report an exception with type mismatch.
OK, I hope everyone is careful when writing programs and don’t make some low-level mistakes.