Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法在Spring MVC中建立JDBC连接_Java_Spring_Spring Mvc - Fatal编程技术网

Java 无法在Spring MVC中建立JDBC连接

Java 无法在Spring MVC中建立JDBC连接,java,spring,spring-mvc,Java,Spring,Spring Mvc,我想将我的SpringMVC应用程序连接到我的本地数据库,但是我遇到了这个错误 Unexpected error occurred in scheduled task.: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot cre

我想将我的SpringMVC应用程序连接到我的本地数据库,但是我遇到了这个错误

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'.)
但是,当我将它连接到另一台服务器上的数据库时,它就成功连接了! 这是我的spring-database.xml文件

<?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>

当我连接到其他服务器而不是本地主机时,我的应用程序工作正常

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

我的环境变量设置正确,因为我可以通过cmd访问我的数据库,
mysql-uroot-p
请帮忙


谢谢你

我不知道你安装的MySQL的版本,我认为它是版本8。正在工作的数据库可能是较旧的安装,其中使用了不同的身份验证机制

在此之前已讨论过该问题:

最好是更新连接器,我认为:


否则,您可以查看手册,了解如何更改标识以允许使用mysql_native_密码:

而不知道mysql安装的版本,我认为这是版本8安装。正在工作的数据库可能是较旧的安装,其中使用了不同的身份验证机制

在此之前已讨论过该问题:

最好是更新连接器,我认为:


否则,您可以查看手册,了解如何更改标识以允许使用mysql\u native\u密码:

谢谢,我使用了一个旧的mysql连接器,我下载了一个新的,现在它工作了谢谢,我使用了一个旧的mysql连接器,我下载了一个新的,现在它工作了