Error: Access restriction: The type 'DataSource' is not API (restriction on required library ..\rt.jar)

Error: Access restriction: The type 'DataSource' is not API (restriction on required library ..\rt.jar)

我正在尝试了解如何使用 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 系统库。再补充一下。这应该可以解决您的错误。