Problem: write a new dao interface prompts unit testing:
Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'int' for property 'maxActive'; nested exception is java.lang.NumberFormatException: For input string: "${maxActive}"
When using a placeholder original configuration datasource, the prompt is parsing placeholder $ {maxActive} found without the corresponding attribute.
Loading unit test using properties @PropertySource (value = { "classpath * : jdbc.properties"}) Annotation load configuration file.
After you acknowledge your properties file path is correct and there is the attribute value to find the appropriate information on the Internet as https://my.oschina.net/u/1455908/blog/215953 say that will configure the MapperScannerConigurer mybatis @PropertySource annotation precedence parsing placeholder placeholder since parsing is not directly use the "$ {maxActive}" the string as the value of the configuration item. Is given called "$ {maxActive}" string can not be converted to the corresponding values int.
Solve the problem
The configuration file loading using annotations from the original @PropertySource (value = { "classpath *: jdbc.properties"}) read as follows:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true"></property>
</bean>
MapperScannerConfigurer original configuration does not make changes, as follows:
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.**.dao,com.**.mapper,com.**.test.**.mapper" />
<!--网上说这个name属性值要配置成这个sqlSessionFactoryBeanName名字,我恰好配的就是这个,所以我这里不需要改-->
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
</bean>
So that the problem is solved. But the question remains, why @PropertySource this comment does not ignoreUnresolvablePlaceholders This property can be configured, and can use xml parsing correct way.