0

警告: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:

在 ServletContext 资源 [/WEB-INF/spring/appServlet/dao-context.xml] 中创建名称为“sessionFactory”的 bean 时出错:调用 init 方法失败;嵌套异常是 org.hibernate.exception.GenericJDBCException:无法打开 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

我无法在春季打开 JDBC 连接。我该如何修复它们?

4

0 回答 0