1

I want to connect my Spring MVC application to my local DB, but i am getting this error

Unexpected error occurred in scheduled task.: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Unable to load authentication plugin 'caching_sha2_password'.)

But when i connect it with a database on another server, it gets connected successfully! This is my spring-database.xml file

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
">
    
<tx:annotation-driven proxy-target-class="true" transaction-manager="transactionManager" />

    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <constructor-arg name="dataSource" ref="ds" ></constructor-arg>
    </bean>
    
 
<bean id="ds" class="org.apache.commons.dbcp.BasicDataSource">    
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>    
<property name="url" value="jdbc:mysql://localhost:3306/expense"></property>    
<property name="username" value="root"></property>    
<property name="password" value="shahrukh"></property> 
<property name="removeAbandoned" value="true"/>
<property name="initialSize" value="20" />
<property name="maxActive" value="30" />   
</bean>    
    
<bean id="jt" class="org.springframework.jdbc.core.JdbcTemplate">    
<property name="dataSource" ref="ds"></property>    
</bean>  



<bean id="securitydao" class="com.expense.DaoImpl.SecurityDaoImpl">    
<property name="template" ref="jt"></property>    
</bean> 
<bean id="commondao" class="com.expense.DaoImpl.CommonDaoImpl">    
<property name="template" ref="jt"></property>    
</bean>
<bean id="expdao" class="com.expense.DaoImpl.ExpenseDaoImpl">    
<property name="template" ref="jt"></property>    
</bean>
<bean id="actiondao" class="com.expense.DaoImpl.Level2DaoImpl">    
<property name="template" ref="jt"></property>    
</bean>

<bean id="accountdao" class="com.expense.DaoImpl.AccountDaoImpl">    
<property name="template" ref="jt"></property>    
</bean>

<bean id="crondao" class="com.expense.DaoImpl.CronDaoImpl">    
<property name="template" ref="jt"></property>    
</bean>


<bean id="dumpdao" class="com.expense.DaoImpl.DumpDaoImpl">    
<property name="template" ref="jt"></property>    
</bean>
<bean id="pettydao" class="com.expense.DaoImpl.PettyCashDaoImpl">    
<property name="template" ref="jt"></property>    
</bean>

<bean id="masterdao" class="com.expense.DaoImpl.MasterDaoImpl">    
<property name="template" ref="jt"></property>    
</bean>

<bean id="escalationNotificationDao" class="com.expense.DaoImpl.EscalationNotificationDaoImpl">    
<property name="template" ref="jt"></property>    
</bean>

  
  
  
  <!--=================================================Service Layer Bean============================================= -->

    
    <bean id="securityservice" class="com.expense.ServiceImpl.SecurityServiceImpl">
    </bean>
        <bean id="commonservice" class="com.expense.ServiceImpl.CommonServiceImpl">
    </bean>
    <bean id="expservice" class="com.expense.ServiceImpl.ExpenseServiceImpl">
    </bean>
    <bean id="actionservice" class="com.expense.ServiceImpl.Level2ServiceImpl">
    </bean>
    <bean id="accountservice" class="com.expense.ServiceImpl.AccountServiceImpl">
    </bean>
    <bean id="uploadfile" class="com.expense.FileUpload.FileUploadService"/>
    
    <bean id="pettyuploadfile" class="com.expense.FileUpload.FileUploadServicePettyCash"/>
    
    <bean id="pettyservice" class="com.expense.ServiceImpl.PettyCashServiceImpl"/> 
    
    <bean id="dumpservice" class="com.expense.ServiceImpl.Dump_ServiceImpl"/> 
    
    <bean id="masterservice" class="com.expense.ServiceImpl.MasterServiceImpl"/> 
    
    <bean id="pageaccess" class="com.expense.ServiceImpl.securityaccess_Impl"/> 
    
    <bean id="escalatedNotificationService" class="com.expense.ServiceImpl.EscalationNotificationServiceImpl"/> 
</beans>

My application works properly is i connect to other serve rather than localhost

<property name="url" value="jdbc:mysql://10.10.1.161:3305/expense"></property> 

My environment variables are set properly, as i am able to access to my database via cmd, mysql -uroot -p Please help.

Thank You

1 Answers1

0

Without knowing anything about the version of your MySQL installation, i think it is a version 8 installation. The one DB that is working is probably an older installation, where a different authentication mechanism is used.

The issue has been discussed before here: How to resolve Unable to load authentication plugin 'caching_sha2_password' issue

Best thing should be to update your connector i think: https://dev.mysql.com/downloads/connector/j/

Otherwise you could check the manual on how to alter the identification to allow mysql_native_password: https://dev.mysql.com/doc/refman/8.0/en/caching-sha2-pluggable-authentication.html

thommyberglund
  • 104
  • 1
  • 8
  • Thank you, i had used an old mysql connector, i downloaded a new one, now its working –  Nov 14 '20 at 09:06