无法创建poolableconnectionfactory并打开jdbc连接

8fsztsew  于 2021-06-20  发布在  Mysql
关注(0)|答案(0)|浏览(316)

警告:org.hibernate.engine.jdbc.spi.sqlexceptionhelper-sql错误:0,sqlstate:null错误:
org.hibernate.engine.jdbc.spi.sqlexceptionhelper-无法创建poolableconnectionfactory(拒绝访问用户“root”@“localhost”(使用密码:yes))
警告:org.springframework.web.context.support.xmlwebapplicationcontext-上下文初始化期间遇到异常-取消刷新尝试:org.springframework.beans.factory.beancreationexception:
创建名为“sessionfactory”的bean时出错,该bean在servletcontext资源[/web-inf/spring/appservlet/dao-context.xml]中定义:调用init方法失败;嵌套异常为org.hibernate.exception.genericjdbception:无法打开jdbc
数据源配置

<?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: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/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">

    <context:property-placeholder location="/WEB-INF/props/jdbc.properties" />

    <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource"
        destroy-method="close">
        <property name="driverClassName" value="${jdbc.driverClassName}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
    </bean>

    <context:annotation-config></context:annotation-config>

    <context:component-scan base-package="kr.ac.hansung.cse.dao">
    </context:component-scan>

    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
        <property name="packagesToScan">
            <list>
                <value>kr.ac.hansung.cse.model</value>
            </list>
        </property>

        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.format_sql">false</prop>
            </props>
        </property>
    </bean>

    <tx:annotation-driven transaction-manager="transactionManager" />

    <bean id="transactionManager"
        class="org.springframework.orm.hibernate5.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>

</beans>

jdbc属性文件

jdbc.username=root
jdbc.password=root
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/estore

我无法在spring中打开jdbc连接。我怎样才能修好它们?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题