简体   繁体   English

无法在 Weblogic 上部署

[英]Impossible to deploy on Weblogic

I tried to apply all the solutions in these questions:我试图在这些问题中应用所有解决方案:

Tomcat vs Weblogic JNDI Lookup Tomcat 与 Weblogic JNDI 查找

javax.naming.NameNotFoundException:while trying to lookup jdbc javax.naming.NameNotFoundException:试图查找 jdbc

but they didn't solve my problem.但他们没有解决我的问题。 I'm using Maven and WebLogic.我正在使用 Maven 和 WebLogic。

In my web.xml I used the tag 'res-ref-name'.在我的 web.xml 中,我使用了标签“res-ref-name”。

Thanks a lot!非常感谢!

You have registered your data source withh the name " jndi /ConsipGfrDS", but looking up with " jdbc /ConsipGfrDS".您已使用名称“ jndi /ConsipGfrDS”注册数据源,但使用“ jdbc /ConsipGfrDS”查找。 Use one (no matter what, but the same) name in both cases.在这两种情况下都使用一个(无论如何,但相同的)名称。

I'd suggest that you use in JNDI the name " jdbc /ConsipGfrDS", because it will be easier to sort objects out if you have many objects in JNDI.我建议您在 JNDI 中使用名称“ jdbc /ConsipGfrDS”,因为如果您在 JNDI 中有很多对象,那么将对象分类会更容易。

This is old fashioned JNDI and you have a couple of problems here.这是老式的 JNDI,这里有几个问题。

Your web.xml has correctly defined您的web.xml已正确定义

<res-ref-name>jdbc/ConsipGfrDS</res-ref-name>

These resource references define names in the JNDI java:comp/env namespace, otherwise known as the component environment namespace which is local to your web application.这些资源引用在 JNDI java:comp/env命名空间中定义名称,也称为 web 应用程序本地的组件环境命名空间。 This means that the full JNDI name of your datasource in your web application is actually java:comp/env/jdbc/ConsipGfrDS , so your lookup code should be:这意味着 web 应用程序中数据源的完整 JNDI 名称实际上是java:comp/env/jdbc/ConsipGfrDS ,因此您的查找代码应该是:

@Bean
public DataSource dataSource() throws NamingException {
    Context ctx = new InitialContext();
    return (DataSource)ctx.lookup("java:comp/env/jdbc/ConsipGfrDS");
}

So far we have platform independent (ie application server) code.到目前为止,我们已经有了独立于平台(即应用服务器)的代码。 You have correctly pushed the platform dependent part into the weblogic.xml file.您已将平台相关部分正确推送到weblogic.xml文件中。

However this is where your second problem lies.但是,这是您的第二个问题所在。 The weblogic.xml contains a small error. weblogic.xml包含一个小错误。 The weblogic console image that you provided showing the JDBC DataSource configuration says that the JNDI name is jdbc/ConsipGfrDS .您提供的显示 JDBC 数据源配置的 weblogic 控制台图像显示 JNDI 名称为jdbc/ConsipGfrDS Therefore, update it as follows:因此,更新如下:

<?xml version="1.0" encoding="UTF-8" ?>
<weblogic-web-app
    xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://xmlns.oracle.com/weblogic/weblogic-web-app http://http://www.oracle.com/technology/weblogic/weblogic-web-app/1.1/weblogic-web-app.xsd">

    <resource-description>
        <!-- match jndi name in weblogic -->
        <jndi-name>jdbc/ConsipGfrDS</jndi-name>
        <!-- match res-ref-name name in web.xml -->
        <res-ref-name>jdbc/ConsipGfrDS</res-ref-name>
    </resource-description>

</weblogic-web-app>

Have fun!玩得开心!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM