简体   繁体   中英

Spring DriverManagerDataSource not found

I have a spring project and i want to create a bean with the DriverManagerDataSource class. I have looked around and found that most people with this issue didn't have spring-jdbc in their pom.xml so I triple checked and I do have the latest version in my pom.xml.

My rest-servlet.xml:

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://localhost:3306/test"/>
        <property name="username" value="root"/>
        <property name="password" value=""/>
    </bean>

The error:

org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.jdbc.datasource.DriverManagerDataSource] for bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/rest-servlet.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.jdbc.datasource.DriverManagerDataSource

I have checked if its under "external libraries" (I use intelliJ) and i do see the class. Also when i try to type the classname the autocomplete finds it too. Any help or suggestions would be appreciated

Make sure you actually have this class in artifact that is built by IDEA. I guess it is WAR so check that it contains "spring-jdbc-.jar". If not check the scope of spring-jdbc dependency in "pom.xml". It should be compile .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM