Spring+mybatis integration cannot read configuration files

Source: Internet
Author: User

The error is as follows:

Java.sql.SQLException:unkow JDBC Driver: ${jdbc.url}
The remaining errors are not posted, mainly because the configuration file is not read

To read the configuration file code:

<bean class= "Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" lazy-init= "true" > < Property Name= "Systempropertiesmodename" value= "System_properties_mode_override"/> <property name= " Ignoreresourcenotfound "value=" true "/> <property name=" Locations "> <list> <value>classpath: Jdbc.properties</value> </list> </property></bean>

  

<bean id= "DataSource" class= "Com.alibaba.druid.pool.DruidDataSource" init-method= "Init" destroy-method= "Close" > <property name= "url" value= "${jdbc.url}"/> <property name= "username" value= "${jdbc.username}"/> < Property name= "Password" value= "${jdbc.password}"/> The connection Pool Setup code (not related to this error) is omitted here </bean>

MyBatis Code

<bean id= "sqlsessionfactory"class= "Org.mybatis.spring.SqlSessionFactoryBean" > <property name= "dataSource" ref= "DataSource"/> <property Name= "Mapperlocations"value= "Classpath:/com/kt/mybatis/gis/mapper/*mapper.xml"/> <property name= "typealiasespackage" value= " Com.kt.mybatis.model "/>
</bean><bean id= "sqlsessiontemplate"class= "Org.mybatis.spring.SqlSessionTemplate" > <constructor-arg index= "0" ref= "sqlsessionfactory"/></bean><beanclass= "Org.mybatis.spring.mapper.MapperScannerConfigurer" > <property name= "basepackage" value= " Com.kt.mybatis.gis.dao,com.kt.mybatis.model "/> <property name=" Sqlsessionfactorybeanname "value="sqlsessionfactory"/></bean><!--configuring Spring's transaction manager--><bean id=" TransactionManager "class= "Org.springframework.jdbc.datasource.DataSourceTransactionManager" > <property name= "DataSource" ref= " DataSource "/></bean><!--use annotation to define a database transaction scope=" request "so that you can declare transactions directly using @transactional annotations in a class or method-- ><tx:annotation-driven transaction-manager= "TransactionManager"/>

Workaround: Change the name of the color in the MyBatis code snippet

Reason: Look at the online data said, is because in spring use Org.mybatis.spring.mapper.MapperScannerConfigurer for automatic scanning, set the sqlsessionfactory words, May cause Propertyplaceholderconfigurer to fail, that is, an expression such as ${jdbc.username} will not be able to get to the content in the properties file. This is caused by the fact that Mapperscannerconigurer is actually parsing the load bean definition phase, which, if set sqlsessionfactory, causes some classes to be initialized in advance, this time, Propertyplaceholderconfigurer has not had time to replace the variables in the definition, causing the expression to be copied as a string. However, if you do not set the Sqlsessionfactory property, you must ensure that the name Sessionfactory in spring will be sqlsessionfactory, otherwise it will not be automatically injected. or directly define the Mapperfactorybean, or discard the automatic proxy interface mode.

http://www.oschina.net/question/188964_32305

PS: This article for Bo Master original, reprint please indicate source: http://www.cnblogs.com/Y-zhiwei/.

Spring+mybatis integration cannot read configuration files

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.