gpt4 book ai didi

java - 未找到 jdbc 类 spring mvc

转载 作者:行者123 更新时间:2023-11-29 21:49:35 25 4
gpt4 key购买 nike

大家好,我正在使用 spring 和 hibernate 开发一个 Web 应用程序,当我尝试运行它时,出现异常 jdbc 类未找到,但我将 Jdbc-connector 添加到了 pom.xml

<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving
up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources
in the /WEB-INF/views directory -->
<beans:bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<beans:bean id="datasource" class="org.apache.commons.dbcp.BasicDataSource">
<beans:property name="driverClassName" value="com.jdbc.mysql.Driver" />
<beans:property name="url"
value="jdbc:mysql://localhost:3306/gestion_bp" />
<beans:property name="username" value="root"/>
<beans:property name="password" value=""/>
</beans:bean>
<beans:bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<beans:property name="dataSource" ref="datasource"/>
<beans:property name="hibernateProperties">
<beans:props>
<beans:prop key="hibernate.show_sql">true</beans:prop>
<beans:prop key="hibernate.hbm2ddl.auto">update</beans:prop>
<beans:prop key="hibernate.dialect" >org.hibernate.dialect.MySQLDialect</beans:prop>
</beans:props>
</beans:property>
</beans:bean>

<context:component-scan base-package="com.sqli.bap" />
<beans:bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<beans:property name="sessionFactory" ref="sessionFactory"/>
</beans:bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<beans:bean id="PersonneDaoImpl" class="com.sqli.bap.daoImpl.PersonneDaoImpl"/>
<beans:bean id="PersonneMetierImpl" class="com.sqli.bap.metierImpl.PersonneMetierImpl"/>

Pom.xml

    <dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.0.0.Final</version>
</dependency>
<!-- Common pool -->
<dependency>
<groupId>Commons-pool</groupId>
<artifactId>Commons-pool</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>Commons-dbcp</groupId>
<artifactId>Commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<!-- MYSQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>

异常

org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.jdbc.mysql.Driver'
at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1429)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:141)
at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:51)
at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:194)
at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:178)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:450)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1775)
at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:247)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:373)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:358)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1547)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1485)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223

谁能告诉我怎么了非常感谢

最佳答案

您正在使用

<beans:property name="driverClassName" value="com.jdbc.mysql.Driver" />

但一定是

<beans:property name="driverClassName" value="com.mysql.jdbc.Driver" />

关于java - 未找到 jdbc 类 spring mvc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33780015/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com