我正在尝试了解如何使用 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/