java - 错误 : Access restriction: The type 'DataSource' is not API (restriction on required library . .\rt.jar)

标签 java eclipse spring jdbc

我正在尝试了解如何使用 Spring JDBC 框架。

我在 http://www.tutorialspoint.com/spring/spring_jdbc_example.htm 上找到了示例并尝试在我自己的项目中实现。

这是我的例子

package test;

import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate;

public class TestJDBCTemplate {
       private DataSource dataSource;
       private JdbcTemplate jdbcTemplateObject;

       public void setDataSource(DataSource dataSource) {
          this.dataSource = dataSource;
          this.jdbcTemplateObject = new JdbcTemplate(dataSource);
       }

}

但是我遇到了问题

import javax.sql.DataSource

访问限制:“DataSource”类型不是 API(对所需库“C:\Program Files (x86)\Java\jre1.8.0_31\lib\rt.jar”的限制)

此导入有什么问题以及如何修复它。 这种导入我在所有有关 Spring JDBC 框架的示例中都见过。

最佳答案

转到 Eclipse 中项目的构建路径设置。删除JRE系统库。再次添加。这应该可以解决您的错误。

关于java - 错误 : Access restriction: The type 'DataSource' is not API (restriction on required library . .\rt.jar),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29911795/

相关文章:

java - 如何在 Spring Data JPA 中使用 After 和 Equals 创建方法名称?

java - 为不同的类执行相同的功能

java - 匹配模式 Gig1/2 和 Gig1/2/3 的通用正则表达式

java - Eclipse 插件开发 : How to drag element from Desktop to custom Node in Project Explorer

java - Android - .getInputStream() 不断崩溃

java - Spring Boot 在使用 uritemplating 时不加载 css

java - webview 不加载我的 html

java - 无法使用返回 play.mvc.WebSocket 的方法作为 Play 中请求的处理程序?

java - 按照 Eclipse 中的功能接口(interface)生成具有正确签名的方法

java - 如何使 Hibernate Spring Repository 返回 HashMap