[英]JNDI lookup failed for the resource Type: javax.sql.DataSource
[英]Object of type [class java.util.Properties] available at JNDI location [comp/env/test] is not assignable to [javax.sql.DataSource]
我需要将Spring MVC应用程序连接到Oracle数据库抛出的Glassfish服务器。
这是我的MVCconfiguration.java
@Bean
public DataSource getDataSource() throws SQLException {
//Option 1 it works
//DriverManagerDataSource dataSource = new DriverManagerDataSource();
//dataSource.setDriverClassName("oracle.jdbc.driver.OracleDriver");
//dataSource.setUrl("jdbc:oracle:thin:@xxx.xx.xx.xx:1521:dtest");
//dataSource.setUsername("user");
//dataSource.setPassword("pass");
//Option 2 didn't work
JndiObjectFactoryBean bean = new JndiObjectFactoryBean();
DataSource dataSource = null;
JndiTemplate jndi = new JndiTemplate();
try {
dataSource = jndi.lookup("comp/env/test", DataSource.class);
} catch (NamingException e) {
}
//Option 3 didn't work
JndiDataSourceLookup dataSourceLookup = new JndiDataSourceLookup();
DataSource dataSource = (DataSource) dataSourceLookup.getDataSource("comp/env/test");
return dataSource;
}
在glassfish中,有一个jdbc资源和jndi自定义资源
但是,当我部署war文件时,出现以下错误:
在JNDI位置[comp / env / test]可用的类型为[class java.util.Properties]的对象不能分配给[javax.sql.DataSource]。
JNDI定制资源是一个java.util.properties JDBC资源,它与JDBC连接池有关(可以是javax.sql.datasource )
只需删除JNDI自定义资源,然后使用JDBC资源即可
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.