春季 MVC Web 应用程序尝试连接到 Oracle 时出错:类型不匹配:无法从驱动程序管理器数据源转换为数据源


I am working on a Spring MVC web app and trying to simply connect to an Oracle database 
(to select the job status info stored in a table). I carefully installed Oracle 
ojdbc7.jar into the Maven respository and added the dependency into my pom.xml, created 
the DAO class, DAOimpl class and added the following into my WebConfig class:
public DataSource dataSource() {
DriverManagerDataSource ds = new DriverManagerDataSource();
ds.setDriverClassName(oracle.jdbc.driver.OracleDriver.class.getName());
ds.setUrl("jdbc:oracle:thin:@<server>:1521:<sid>");
ds.setUsername("user");
ds.setPassword("*****");
return ds;
But WebConfig will not compile because of: Type mismatch 
on ds: cannot convert from 
DriverManagerDataSource to DataSource
Has anyone experienced this issue? And what was the solution?

如果您需要更多信息,请告诉我(请善待 - 我是 java 新手(

顺便说一句,为了构建弹簧MVC CRUD,我访问了以下网站: https://www.codejava.net/frameworks/spring-boot/spring-boot-crud-web-application-with-jdbc-thymeleaf-oracle

https://javainterviewpoint.com/spring-crud-example-jdbctemplate/

https://www.javatpoint.com/spring-mvc-crud-example

谢谢

这是我的诗:

<dependencies>
<!-- Spring MVC Dependency -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<!-- JSTL Dependency -->
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>javax.servlet.jsp.jstl-api</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<!-- Servlet Dependency -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<!-- JSP Dependency -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.oracle</groupId>
<artifactId>ora-jdbc</artifactId>
<version>7</version>
</dependency>
<dependency>  
<groupId>org.springframework</groupId>  
<artifactId>spring-jdbc</artifactId>  
<version>5.1.1.RELEASE</version>  
</dependency>   
</dependencies> 
<build> 
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin> 
<groupId>com.googlecode.addjars-maven-plugin</groupId> 
<artifactId>addjars-maven-plugin</artifactId> 
<version>1.0.5</version> 
<executions> 
<execution> 
<goals>  
<goal>add-jars</goal> 
</goals> 
<configuration> 
<resources> 
<resource> 
<directory>${basedir}/lib</directory> 
<includes> 
<include>**/*.jar</include> 
</includes> 
</resource> 
</resources> 
</configuration> 
</execution> 
</executions> 
</plugin> 
<!-- Embedded Apache Tomcat required for testing war -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/</path>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>

正如错误所说,datasource()方法中的DatasourceDriverManagerDataSource之间存在类型不匹配。

请确保导入正确的依赖项。

Datasource应该是:javax.sql.DataSourceDriverManagerDataSource应该是:org.springframework.jdbc.datasource.DriverManagerDataSource