Weblogic exception : javax.naming.NameNotFoundException: Unable to resolve 'jdbc.payment'. Resolved 'jdbc'; remaining name 'payment'

huangapple go评论81阅读模式
英文:

Weblogic exception : javax.naming.NameNotFoundException: Unable to resolve 'jdbc.payment'. Resolved 'jdbc'; remaining name 'payment'

问题

在从Spring Boot应用程序查找WebLogic中的JNDI数据源时,我遇到了这个异常... 仅在第一次成功部署之后... 我是说从第二次部署开始。如果我重新启动容器,那么仅对于第一次部署,它将正常工作。

导致此问题的原因是:javax.naming.NameNotFoundException: 无法解析 'jdbc.payment'。已解析 'jdbc';剩余名称 'payment'。

具有相同名称并附加到管理员服务器的数据源。

我使用的Docker镜像是:store/oracle/weblogic:12.2.1.4-dev,带有环境变量 PRODUCTION_MODE=dev

更新:如果我从服务器中分离数据源,然后重新连接,然后启动war文件,它会再次成功运行一次。

更新:已切换到本地安装的WebLogic,不再使用Docker,但问题仍然存在。

英文:

I have this exception when I lookup jndi datasource from weblogic from spring boot application...only after one successful deployment...I mean from the second deployment on.If I restart the container, it will work fine for the first deployment only.

Caused by: javax.naming.NameNotFoundException: Unable to resolve 'jdbc.payment'. Resolved 'jdbc'; remaining name 'payment'

the datasource with the same name and attached to the admin server.

I use docker image : store/oracle/weblogic:12.2.1.4-dev with environment variable PRODUCTION_MODE=dev

update : if I deattach the data source from the server then reattche it again then start the war, It runs successfully for one time againز

update : switched to local installation of weblogic not dockerized any more and the behavior still happens

答案1

得分: 3

这是一个春季问题...与Weblogic无关。

在关闭中,Spring从服务器JNDI树中删除数据源,但数据源仍在服务器上运行。
重新创建甚至重新附加数据源到目标服务器,将其再次添加到JNDI树中。

解决此行为的解决方法是阻止Spring调用数据源bean的销毁方法

@Primary
@Bean(name = "dataSource",destroyMethod = "")
@Profile("weblogic")
public DataSource dataSourceWeblogic() throws NamingException {

		JndiTemplate jndiTemplate = new JndiTemplate();
		InitialContext ctx = (InitialContext) jndiTemplate.getContext();
    	return  (javax.sql.DataSource) ctx.lookup(jndi);
}
英文:

It's a spring issue...has nothing to do with weblogic.

In the war shutdown, Spring remove the data source form the server JNDI tree, however the data source still up and running on the server.
The action of recreating or even reattaching the data source to target server, add it again to the JNDI tree.

The workaround to solve this behavior is to prevent spring from calling the destroy method of the data source bean

@Primary
@Bean(name = "dataSource",destroyMethod = "")
@Profile("weblogic")
public DataSource dataSourceWeblogic() throws NamingException {

		JndiTemplate jndiTemplate = new JndiTemplate();
		InitialContext ctx = (InitialContext) jndiTemplate.getContext();
    	return  (javax.sql.DataSource) ctx.lookup(jndi);
}

huangapple
  • 本文由 发表于 2020年9月3日 22:24:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/63725675.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定