Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WebSphere Liberty+;Springboot&x2B;冬眠+;JNDI_Spring_Spring Boot_Jndi_Websphere Liberty_Open Liberty - Fatal编程技术网

WebSphere Liberty+;Springboot&x2B;冬眠+;JNDI

WebSphere Liberty+;Springboot&x2B;冬眠+;JNDI,spring,spring-boot,jndi,websphere-liberty,open-liberty,Spring,Spring Boot,Jndi,Websphere Liberty,Open Liberty,我正在尝试将我的小应用程序从Tomcat迁移到WebSphere。为了做到这一点,我正在从头开始重建它,分别处理主要组件。我正在努力解决WebSphereLiberty上的数据访问/JNDI问题。我明白了 javax.naming.NameNotFoundException:javax.naming.NameNotFoundException:java:comp/env/jdbc/test SERVER.xml <featureManager> <feature>webP

我正在尝试将我的小应用程序从Tomcat迁移到WebSphere。为了做到这一点,我正在从头开始重建它,分别处理主要组件。我正在努力解决WebSphereLiberty上的数据访问/JNDI问题。我明白了

javax.naming.NameNotFoundException:javax.naming.NameNotFoundException:java:comp/env/jdbc/test

SERVER.xml

<featureManager>
<feature>webProfile-8.0</feature>
<feature>localConnector-1.0</feature>
<feature>adminCenter-1.0</feature>
<feature>javaee-8.0</feature>
<feature>jndi-1.0</feature>
<feature>concurrent-1.0</feature>
我也尝试过这种方法:

@Bean
public DataSource dataSource() throws NamingException {
    return (DataSource) new JndiTemplate().lookup("java:comp/env/jdbc/test");
}

我注意到的第一件事是,在server.xml中有2个
元素——应该只使用一个,如下所示:


接下来,您将定义如下所示的资源引用:

@Resource(lookup=“java:comp/env/jdbc/test”,name=“java:comp/env/jdbc/test”)
私有数据源;
这实际上是说“创建一个JNDI查找‘java:comp/env/jdbc/test’并将其绑定到‘java:comp/env/jdbc/test’JNDI名称”。这将导致无限循环或循环引用

相反,您希望将
查找
绑定到您在server.xml中定义的
jndiName
,如下所示:

@Resource(lookup=“jdbc/test”,name=“java:comp/env/jdbc/test”)
私有数据源;
或者,如果这不起作用,您可以尝试直接查找Spring方式,如下所示:

@Bean
public DataSource DataSource()引发NamingException{
返回(数据源)新的jndemplate().lookup(“java:comp/env/jdbc/test”);
}
或使用Java标准API:

DataSource ds=javax.naming.InitialContext.doLookup(“jdbc/test”);
如果这些选项都不起作用,请检查服务器日志中的错误或警告。应该有一些指示说明为什么不能创建数据源


Liberty 19.0.0.9中的新功能--数据源验证API 在19.0.0.9中,我们发布了一个RESTAPI,可用于验证配置元素,如
dataSource
s

要将其与配置一起使用,请按如下方式配置管理员用户(如果尚未配置):


然后在web浏览器中转到
https://localhost:9443/ibm/api/validation/dataSource/{DATASOURCE_ID}
这将是您的情况


要全面了解此验证功能,请参阅。

这看起来基本正确,只是查找与server.xml中配置的jndiName匹配

@Resource(lookup = "jdbc/test", name="java:comp/env/jdbc/test")
private DataSource dataSource;

您不需要
DataSourceConfig
类。只需在配置中指定
spring.datasource、jndi名称
,spring Boot就会进行查找。谢谢。这很有帮助。我已经移动到10.0.0.9,并使用该实用程序确认我的JNDI工作正常。我仍然对数据有疑问(CRUDepository/JPA可能与Spring有关),但您的回答帮助我向前推进并确认了这一部分。我想我会提出另一个问题,让StackOverflow上的事情保持清晰,避免让其他人感到困惑
@Bean
public DataSource dataSource() throws NamingException {
    return (DataSource) new JndiTemplate().lookup("java:comp/env/jdbc/test");
}
@Resource(lookup = "jdbc/test", name="java:comp/env/jdbc/test")
private DataSource dataSource;