gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 03:46:30 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com